X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Ftests%2Fthreads%2Flist.c;h=836c69ef3fe9644edec51b7552bef56cc4b0fb94;hb=d5aab5fcc001efba94a378535746e71a2e9d92f2;hp=aac583f8bb2b1fd1403856c0a1270922b1fcffdc;hpb=cde006efa42a1708ca98375190f9c153454ef996;p=pintos-anon diff --git a/src/tests/threads/list.c b/src/tests/threads/list.c index aac583f..836c69e 100644 --- a/src/tests/threads/list.c +++ b/src/tests/threads/list.c @@ -21,12 +21,13 @@ /* A linked list element. */ struct value { - list_elem elem; /* List element. */ + struct list_elem elem; /* List element. */ int value; /* Item value. */ }; static void shuffle (struct value[], size_t); -static bool value_less (const list_elem *, const list_elem *, void *); +static bool value_less (const struct list_elem *, const struct list_elem *, + void *); static void verify_list_fwd (struct list *, int size); static void verify_list_bkwd (struct list *, int size); @@ -41,12 +42,12 @@ test (void) { int repeat; - printf (" %zu", size); + printf (" %d", size); for (repeat = 0; repeat < 10; repeat++) { static struct value values[MAX_SIZE * 4]; struct list list; - list_elem *e; + struct list_elem *e; int i, ofs; /* Put values 0...SIZE in random order in VALUES. */ @@ -59,6 +60,14 @@ test (void) for (i = 0; i < size; i++) list_push_back (&list, &values[i].elem); + /* Verify correct minimum and maximum elements. */ + e = list_min (&list, value_less, NULL); + ASSERT (size ? list_entry (e, struct value, elem)->value == 0 + : e == list_begin (&list)); + e = list_max (&list, value_less, NULL); + ASSERT (size ? list_entry (e, struct value, elem)->value == size - 1 + : e == list_begin (&list)); + /* Sort and verify list. */ list_sort (&list, value_less, NULL); verify_list_fwd (&list, size); @@ -96,6 +105,7 @@ test (void) } printf (" done\n"); + printf ("list: PASS\n"); } /* Shuffles the CNT elements in ARRAY into random order. */ @@ -116,7 +126,8 @@ shuffle (struct value *array, size_t cnt) /* Returns true if value A is less than value B, false otherwise. */ static bool -value_less (const list_elem *a_, const list_elem *b_, void *aux UNUSED) +value_less (const struct list_elem *a_, const struct list_elem *b_, + void *aux UNUSED) { const struct value *a = list_entry (a_, struct value, elem); const struct value *b = list_entry (b_, struct value, elem); @@ -129,7 +140,7 @@ value_less (const list_elem *a_, const list_elem *b_, void *aux UNUSED) static void verify_list_fwd (struct list *list, int size) { - list_elem *e; + struct list_elem *e; int i; for (i = 0, e = list_begin (list); @@ -148,7 +159,7 @@ verify_list_fwd (struct list *list, int size) static void verify_list_bkwd (struct list *list, int size) { - list_elem *e; + struct list_elem *e; int i; for (i = 0, e = list_rbegin (list);