Patchwork qtest: add register fuzzing to RTC test

login
register
mail settings
Submitter Blue Swirl
Date April 15, 2012, 7:40 a.m.
Message ID <CAAu8pHvs-j=vgXTijKt=Zcz61=+9vq7=B4Dq38WgUfhOiU4qyg@mail.gmail.com>
Download mbox | patch
Permalink /patch/152591/
State New
Headers show

Comments

Blue Swirl - April 15, 2012, 7:40 a.m.
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 tests/rtc-test.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)
Anthony Liguori - April 16, 2012, 12:34 a.m.
On 04/15/2012 02:40 AM, Blue Swirl wrote:
> Signed-off-by: Blue Swirl<blauwirbel@gmail.com>

Good idea.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Regards,

Anthony Liguori

> ---
>   tests/rtc-test.c |   17 +++++++++++++++++
>   1 file changed, 17 insertions(+)
>
> diff --git a/tests/rtc-test.c b/tests/rtc-test.c
> index 983a980..f23ac3a 100644
> --- a/tests/rtc-test.c
> +++ b/tests/rtc-test.c
> @@ -240,6 +240,22 @@ static void alarm_time(void)
>       g_assert(cmos_read(RTC_REG_C) == 0);
>   }
>
> +/* success if no crash or abort */
> +static void fuzz_registers(void)
> +{
> +    unsigned int i;
> +
> +    for (i = 0; i<  1000; i++) {
> +        uint8_t reg, val;
> +
> +        reg = (uint8_t)g_test_rand_int_range(0, 16);
> +        val = (uint8_t)g_test_rand_int_range(0, 256);
> +
> +        cmos_write(reg, val);
> +        cmos_read(reg);
> +    }
> +}
> +
>   int main(int argc, char **argv)
>   {
>       QTestState *s = NULL;
> @@ -253,6 +269,7 @@ int main(int argc, char **argv)
>       qtest_add_func("/rtc/bcd/check-time", bcd_check_time);
>       qtest_add_func("/rtc/dec/check-time", dec_check_time);
>       qtest_add_func("/rtc/alarm-time", alarm_time);
> +    qtest_add_func("/rtc/fuzz-registers", fuzz_registers);
>       ret = g_test_run();
>
>       if (s) {

Patch

diff --git a/tests/rtc-test.c b/tests/rtc-test.c
index 983a980..f23ac3a 100644
--- a/tests/rtc-test.c
+++ b/tests/rtc-test.c
@@ -240,6 +240,22 @@  static void alarm_time(void)
     g_assert(cmos_read(RTC_REG_C) == 0);
 }

+/* success if no crash or abort */
+static void fuzz_registers(void)
+{
+    unsigned int i;
+
+    for (i = 0; i < 1000; i++) {
+        uint8_t reg, val;
+
+        reg = (uint8_t)g_test_rand_int_range(0, 16);
+        val = (uint8_t)g_test_rand_int_range(0, 256);
+
+        cmos_write(reg, val);
+        cmos_read(reg);
+    }
+}
+
 int main(int argc, char **argv)
 {
     QTestState *s = NULL;
@@ -253,6 +269,7 @@  int main(int argc, char **argv)
     qtest_add_func("/rtc/bcd/check-time", bcd_check_time);
     qtest_add_func("/rtc/dec/check-time", dec_check_time);
     qtest_add_func("/rtc/alarm-time", alarm_time);
+    qtest_add_func("/rtc/fuzz-registers", fuzz_registers);
     ret = g_test_run();

     if (s) {