Changeset 3bacee1 in mainline for kernel/test


Ignore:
Timestamp:
2018-04-12T16:27:17Z (8 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3cf22f9
Parents:
76d0981d
git-author:
Jiri Svoboda <jiri@…> (2018-04-11 19:25:33)
git-committer:
Jiri Svoboda <jiri@…> (2018-04-12 16:27:17)
Message:

Make ccheck-fix again and commit more good files.

Location:
kernel/test
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kernel/test/cht/cht1.c

    r76d0981d r3bacee1  
    9595
    9696
    97 static const char * do_sanity_test(cht_t *h)
    98 {
    99         if (cht_find_lazy(h, (void*)0))
     97static const char *do_sanity_test(cht_t *h)
     98{
     99        if (cht_find_lazy(h, (void *)0))
    100100                return "Found lazy in empty table.";
    101101
    102         if (cht_find(h, (void*)0))
     102        if (cht_find(h, (void *)0))
    103103                return "Found in empty table.";
    104104
    105         if (cht_remove_key(h, (void*)0))
     105        if (cht_remove_key(h, (void *)0))
    106106                return "Removed from empty table.";
    107107
     
    149149                return "Refused unique ins 4, 5.";
    150150
    151         if (cht_find(h, (void*)0))
     151        if (cht_find(h, (void *)0))
    152152                return "Phantom find.";
    153153
    154         cht_link_t *item = cht_find(h, (void*)v[5]->unique_id);
     154        cht_link_t *item = cht_find(h, (void *)v[5]->unique_id);
    155155        if (!item || item != &v[5]->link)
    156156                return "Missing 5.";
     
    160160                return "Found nonexisting duplicate 5";
    161161
    162         item = cht_find(h, (void*)v[3]->unique_id);
     162        item = cht_find(h, (void *)v[3]->unique_id);
    163163        if (!item || item != &v[3]->link)
    164164                return "Missing 3.";
     
    168168                return "Found nonexisting duplicate 3, same hash as others.";
    169169
    170         item = cht_find(h, (void*)v[0]->unique_id);
    171         ((val_t*)item)->mark = true;
     170        item = cht_find(h, (void *)v[0]->unique_id);
     171        ((val_t *)item)->mark = true;
    172172
    173173        for (int k = 1; k < 3; ++k) {
     
    176176                        return "Did not find an inserted duplicate";
    177177
    178                 val_t *val = ((val_t*)item);
     178                val_t *val = ((val_t *)item);
    179179
    180180                if (val->unique_id != v[0]->unique_id)
     
    195195                return "Found non-existing duplicate.";
    196196
    197         item = cht_find_next(h, cht_find(h, (void*)key[0]));
    198 
    199         ((val_t*)item)->mark = true;
     197        item = cht_find_next(h, cht_find(h, (void *)key[0]));
     198
     199        ((val_t *)item)->mark = true;
    200200        if (!cht_remove_item(h, item))
    201201                return "Failed to remove inserted item";
    202202
    203         item = cht_find(h, (void*)key[0]);
    204         if (!item || ((val_t*)item)->mark)
     203        item = cht_find(h, (void *)key[0]);
     204        if (!item || ((val_t *)item)->mark)
    205205                return "Did not find proper item.";
    206206
    207207        item = cht_find_next(h, item);
    208         if (!item || ((val_t*)item)->mark)
     208        if (!item || ((val_t *)item)->mark)
    209209                return "Did not find proper duplicate.";
    210210
     
    213213                return "Found removed duplicate";
    214214
    215         if (2 != cht_remove_key(h, (void*)key[0]))
     215        if (2 != cht_remove_key(h, (void *)key[0]))
    216216                return "Failed to remove all duplicates";
    217217
    218         if (cht_find(h, (void*)key[0]))
     218        if (cht_find(h, (void *)key[0]))
    219219                return "Found removed key";
    220220
    221         if (!cht_find(h, (void*)key[3]))
     221        if (!cht_find(h, (void *)key[3]))
    222222                return "Removed incorrect key";
    223223
    224224        for (size_t k = 0; k < sizeof(v) / sizeof(v[0]); ++k) {
    225                 cht_remove_key(h, (void*)key[k]);
     225                cht_remove_key(h, (void *)key[k]);
    226226        }
    227227
    228228        for (size_t k = 0; k < sizeof(v) / sizeof(v[0]); ++k) {
    229                 if (cht_find(h, (void*)key[k]))
     229                if (cht_find(h, (void *)key[k]))
    230230                        return "Found a key in a cleared table";
    231231        }
     
    234234}
    235235
    236 static const char * sanity_test(void)
     236static const char *sanity_test(void)
    237237{
    238238        cht_t h;
     
    279279static size_t stress_hash(const cht_link_t *item)
    280280{
    281         return ((stress_t*)item)->key >> 8;
     281        return ((stress_t *)item)->key >> 8;
    282282}
    283283static size_t stress_key_hash(void *key)
     
    287287static bool stress_equal(const cht_link_t *item1, const cht_link_t *item2)
    288288{
    289         return ((stress_t*)item1)->key == ((stress_t*)item2)->key;
     289        return ((stress_t *)item1)->key == ((stress_t *)item2)->key;
    290290}
    291291static bool stress_key_equal(void *key, const cht_link_t *item)
    292292{
    293         return ((size_t)key) == ((stress_t*)item)->key;
     293        return ((size_t)key) == ((stress_t *)item)->key;
    294294}
    295295static void stress_rm_callback(cht_link_t *item)
    296296{
    297         if (((stress_t*)item)->free)
     297        if (((stress_t *)item)->free)
    298298                free(item);
    299299        else
    300                 ((stress_t*)item)->deleted = true;
     300                ((stress_t *)item)->deleted = true;
    301301}
    302302
     
    335335                        size_t key = (i << 8) + work->id;
    336336
    337                         if (1 != cht_remove_key(work->h, (void*)key)) {
     337                        if (1 != cht_remove_key(work->h, (void *)key)) {
    338338                                TPRINTF("Err: Failed to remove inserted item\n");
    339339                                goto failed;
     
    357357        for (size_t i = 0; i < work->wave_elems; ++i) {
    358358                size_t key = (i << 8) + work->id;
    359                 cht_remove_key(work->h, (void*)key);
     359                cht_remove_key(work->h, (void *)key);
    360360        }
    361361}
     
    392392                                        rcu_read_unlock();
    393393                                } else {
    394                                         void *key = (void*)work->elem[elem_idx].key;
     394                                        void *key = (void *)work->elem[elem_idx].key;
    395395                                        if (1 != cht_remove_key(work->h, key)) {
    396396                                                TPRINTF("Err: did not rm the key\n");
     
    406406                                        cht_link_t *dup;
    407407                                        if (!cht_insert_unique(work->h, &work->elem[elem_idx].link,
    408                                                 &dup)) {
     408                                            &dup)) {
    409409                                                TPRINTF("Err: already inserted\n");
    410410                                                work->failed = true;
     
    420420                        rcu_read_lock();
    421421                        cht_link_t *item =
    422                                 cht_find(work->h, (void*)work->elem[elem_idx].key);
     422                            cht_find(work->h, (void *)work->elem[elem_idx].key);
    423423                        rcu_read_unlock();
    424424
     
    444444        /* Remove anything we may have inserted. */
    445445        for (size_t i = 0; i < work->elem_cnt; ++i) {
    446                 void *key = (void*) work->elem[i].key;
     446                void *key = (void *) work->elem[i].key;
    447447                cht_remove_key(work->h, key);
    448448        }
     
    469469
    470470        /* Alloc hash table items. */
    471         size_t size = item_cnt * sizeof(stress_t) + work_cnt * sizeof(stress_work_t)
    472                 + sizeof(int);
     471        size_t size = item_cnt * sizeof(stress_t) + work_cnt * sizeof(stress_work_t) +
     472            sizeof(int);
    473473
    474474        TPRINTF("Alloc and init table items. \n");
     
    482482        stress_t *pitem = p + work_cnt * sizeof(stress_work_t);
    483483        stress_work_t *pwork = p;
    484         int *pstop = (int*)(pitem + item_cnt);
     484        int *pstop = (int *)(pitem + item_cnt);
    485485
    486486        *pstop = 0;
     
    517517
    518518        TPRINTF("Running %zu ins/del/find stress threads + %zu resizers.\n",
    519                 op_thread_cnt, resize_thread_cnt);
     519            op_thread_cnt, resize_thread_cnt);
    520520
    521521        /* Create and run threads. */
  • kernel/test/synch/rcu1.c

    r76d0981d r3bacee1  
    7878}
    7979
    80 static void run_thread(size_t k, void (*func)(void*), void *arg)
     80static void run_thread(size_t k, void (*func)(void *), void *arg)
    8181{
    8282        assert(thread[k] == NULL);
    8383
    8484        thread[k] = thread_create(func, arg, TASK, THREAD_FLAG_NONE,
    85                 "test-rcu-thread");
    86 
    87         if(thread[k]) {
     85            "test-rcu-thread");
     86
     87        if (thread[k]) {
    8888                /* Distribute evenly. */
    8989                thread_wire(thread[k], &cpus[k % config.cpu_active]);
     
    9292}
    9393
    94 static void run_all(void (*func)(void*))
     94static void run_all(void (*func)(void *))
    9595{
    9696        size_t thread_cnt = get_thread_cnt();
     
    127127}
    128128
    129 static void run_one(void (*func)(void*), void *arg)
     129static void run_one(void (*func)(void *), void *arg)
    130130{
    131131        assert(one_idx < MAX_THREADS);
     
    179179static bool do_nop_readers(void)
    180180{
    181         size_t seq[MAX_THREADS] = {0};
     181        size_t seq[MAX_THREADS] = { 0 };
    182182        get_seq(100, 100000, get_thread_cnt(), seq);
    183183
     
    185185
    186186        for (size_t k = 0; k < get_thread_cnt(); ++k)
    187                 run_one(nop_reader, (void*)seq[k]);
     187                run_one(nop_reader, (void *)seq[k]);
    188188
    189189        TPRINTF("\nJoining %zu no-op readers\n", get_thread_cnt());
     
    220220static bool do_long_readers(void)
    221221{
    222         size_t seq[MAX_THREADS] = {0};
     222        size_t seq[MAX_THREADS] = { 0 };
    223223        get_seq(10, 1000 * 1000, get_thread_cnt(), seq);
    224224
    225225        TPRINTF("\nRun %zu thr: repeat long reader sections, will preempt, no cbs.\n",
    226                 get_thread_cnt());
     226            get_thread_cnt());
    227227
    228228        for (size_t k = 0; k < get_thread_cnt(); ++k)
    229                 run_one(long_reader, (void*)seq[k]);
     229                run_one(long_reader, (void *)seq[k]);
    230230
    231231        TPRINTF("\nJoining %zu readers with long reader sections.\n", get_thread_cnt());
     
    238238
    239239
    240 static atomic_t nop_callbacks_cnt = {0};
     240static atomic_t nop_callbacks_cnt = { 0 };
    241241/* Must be even. */
    242242static const int nop_updater_iters = 10000;
     
    250250static void nop_updater(void *arg)
    251251{
    252         for (int i = 0; i < nop_updater_iters; i += 2){
     252        for (int i = 0; i < nop_updater_iters; i += 2) {
    253253                rcu_item_t *a = malloc(sizeof(rcu_item_t), FRAME_ATOMIC);
    254254                rcu_item_t *b = malloc(sizeof(rcu_item_t), FRAME_ATOMIC);
     
    274274
    275275        TPRINTF("\nRun %zu thr: post %zu no-op callbacks (%zu B used), no readers.\n",
    276                 get_thread_cnt(), exp_cnt, max_used_mem);
     276            get_thread_cnt(), exp_cnt, max_used_mem);
    277277
    278278        run_all(nop_updater);
     
    303303static void one_cb_done(rcu_item_t *item)
    304304{
    305         assert( ((item_w_cookie_t *)item)->cookie == magic_cookie);
     305        assert(((item_w_cookie_t *)item)->cookie == magic_cookie);
    306306        one_cb_is_done = 1;
    307307        TPRINTF("Callback()\n");
     
    367367static errno_t seq_test_result = EOK;
    368368
    369 static atomic_t cur_time = {1};
    370 static atomic_count_t max_upd_done_time = {0};
     369static atomic_t cur_time = { 1 };
     370static atomic_count_t max_upd_done_time = { 0 };
    371371
    372372static void seq_cb(rcu_item_t *rcu_item)
     
    392392         */
    393393#ifndef KARCH_riscv64
    394         seq_work_t *work = (seq_work_t*)arg;
     394        seq_work_t *work = (seq_work_t *)arg;
    395395
    396396        /* Alternate between reader and updater roles. */
     
    401401                        atomic_count_t start_time = atomic_postinc(&cur_time);
    402402
    403                         for (volatile size_t d = 0; d < 10 * i; ++d ){
     403                        for (volatile size_t d = 0; d < 10 * i; ++d) {
    404404                                /* no-op */
    405405                        }
     
    452452        const size_t iters = 100;
    453453        const size_t total_cnt = 1000;
    454         size_t read_cnt[MAX_THREADS] = {0};
     454        size_t read_cnt[MAX_THREADS] = { 0 };
    455455        seq_work_t item[MAX_THREADS];
    456456
     
    476476
    477477        TPRINTF("\nRun %zu th: check callback completion time in readers. "
    478                 "%zu callbacks total (max %" PRIu64 " %s used). Be patient.\n",
    479                 get_thread_cnt(), total_cbs, mem_units, mem_suffix);
     478            "%zu callbacks total (max %" PRIu64 " %s used). Be patient.\n",
     479            get_thread_cnt(), total_cbs, mem_units, mem_suffix);
    480480
    481481        for (size_t i = 0; i < get_thread_cnt(); ++i) {
     
    500500static void reader_unlocked(rcu_item_t *item)
    501501{
    502         exited_t *p = (exited_t*)item;
     502        exited_t *p = (exited_t *)item;
    503503        p->exited = true;
    504504}
     
    511511        rcu_read_unlock();
    512512
    513         rcu_call((rcu_item_t*)arg, reader_unlocked);
     513        rcu_call((rcu_item_t *)arg, reader_unlocked);
    514514
    515515        rcu_read_lock();
     
    566566static void preempted_reader_prev(void *arg)
    567567{
    568         preempt_t *p = (preempt_t*)arg;
     568        preempt_t *p = (preempt_t *)arg;
    569569        assert(!p->e.exited);
    570570
     
    586586static void preempted_reader_inside_cur(void *arg)
    587587{
    588         preempt_t *p = (preempt_t*)arg;
     588        preempt_t *p = (preempt_t *)arg;
    589589        assert(!p->e.exited);
    590590
     
    611611static void preempted_reader_cur(void *arg)
    612612{
    613         preempt_t *p = (preempt_t*)arg;
     613        preempt_t *p = (preempt_t *)arg;
    614614        assert(!p->e.exited);
    615615
     
    633633static void preempted_reader_next1(void *arg)
    634634{
    635         preempt_t *p = (preempt_t*)arg;
     635        preempt_t *p = (preempt_t *)arg;
    636636        assert(!p->e.exited);
    637637
     
    655655static void preempted_reader_next2(void *arg)
    656656{
    657         preempt_t *p = (preempt_t*)arg;
     657        preempt_t *p = (preempt_t *)arg;
    658658        assert(!p->e.exited);
    659659
     
    684684
    685685
    686 static bool do_one_reader_preempt(void (*f)(void*), const char *err)
     686static bool do_one_reader_preempt(void (*f)(void *), const char *err)
    687687{
    688688        preempt_t *p = malloc(sizeof(preempt_t), FRAME_ATOMIC);
     
    719719
    720720        ok = do_one_reader_preempt(preempted_reader_prev,
    721                 "Err: preempted_reader_prev()\n");
     721            "Err: preempted_reader_prev()\n");
    722722        success = success && ok;
    723723
    724724        ok = do_one_reader_preempt(preempted_reader_inside_cur,
    725                 "Err: preempted_reader_inside_cur()\n");
     725            "Err: preempted_reader_inside_cur()\n");
    726726        success = success && ok;
    727727
    728728        ok = do_one_reader_preempt(preempted_reader_cur,
    729                 "Err: preempted_reader_cur()\n");
     729            "Err: preempted_reader_cur()\n");
    730730        success = success && ok;
    731731
    732732        ok = do_one_reader_preempt(preempted_reader_next1,
    733                 "Err: preempted_reader_next1()\n");
     733            "Err: preempted_reader_next1()\n");
    734734        success = success && ok;
    735735
    736736        ok = do_one_reader_preempt(preempted_reader_next2,
    737                 "Err: preempted_reader_next2()\n");
     737            "Err: preempted_reader_next2()\n");
    738738        success = success && ok;
    739739
     
    860860static void stress_reader(void *arg)
    861861{
    862         bool *done = (bool*) arg;
     862        bool *done = (bool *) arg;
    863863
    864864        while (!*done) {
     
    896896
    897897                /* Print a dot if we make a progress of 1% */
    898                 if (s->master && 0 == (i % (s->iters/100)))
     898                if (s->master && 0 == (i % (s->iters / 100)))
    899899                        TPRINTF(".");
    900900        }
     
    921921
    922922        TPRINTF("\nStress: Run %zu nop-readers and %zu updaters. %zu callbacks"
    923                 " total (max %" PRIu64 " %s used). Be very patient.\n",
    924                 reader_cnt, updater_cnt, exp_upd_calls, mem_units, mem_suffix);
     923            " total (max %" PRIu64 " %s used). Be very patient.\n",
     924            reader_cnt, updater_cnt, exp_upd_calls, mem_units, mem_suffix);
    925925
    926926        for (size_t k = 0; k < reader_cnt; ++k) {
     
    961961                --e->count_down;
    962962
    963                 if (0 == (e->count_down % (e->total_cnt/100))) {
     963                if (0 == (e->count_down % (e->total_cnt / 100))) {
    964964                        TPRINTF("*");
    965965                }
     
    10461046                if (ok) {
    10471047                        TPRINTF("\nSubtest %s() ok (GPs: %" PRIu64 ").\n",
    1048                                 test_func[i].desc, delta_gps);
     1048                            test_func[i].desc, delta_gps);
    10491049                } else {
    10501050                        TPRINTF("\nFailed: %s(). Pausing for 5 secs.\n", test_func[i].desc);
  • kernel/test/synch/workq-test-core.h

    r76d0981d r3bacee1  
    6767{
    6868        unsigned n = (unsigned)num;
    69         return (n != 0) && 0 == (n & (n-1));
    70 }
    71 
    72 static test_work_t * create_child(test_work_t *work)
     69        return (n != 0) && 0 == (n & (n - 1));
     70}
     71
     72static test_work_t *create_child(test_work_t *work)
    7373{
    7474        test_work_t *child = malloc(sizeof(test_work_t), 0);
     
    168168
    169169        TPRINTF("waves: %d, count_down: %d, total expected calls: %zu\n",
    170                 WAVES, COUNT, exp_call_cnt * WAVES);
     170            WAVES, COUNT, exp_call_cnt * WAVES);
    171171
    172172
     
    179179
    180180        for (int i = 0; i < WAVES; ++i) {
    181                 while (atomic_get(&call_cnt[i]) < exp_call_cnt
    182                         && sleep_cnt < max_sleep_cnt) {
     181                while (atomic_get(&call_cnt[i]) < exp_call_cnt &&
     182                    sleep_cnt < max_sleep_cnt) {
    183183                        TPRINTF(".");
    184184                        thread_usleep(MAIN_POLL_SLEEP_MS * 1000);
     
    192192                if (atomic_get(&call_cnt[i]) == exp_call_cnt) {
    193193                        TPRINTF("Ok: %" PRIua " calls in wave %d, as expected.\n",
    194                                 atomic_get(&call_cnt[i]), i);
     194                            atomic_get(&call_cnt[i]), i);
    195195                } else {
    196196                        success = false;
    197197                        TPRINTF("Error: %" PRIua " calls in wave %d, but %zu expected.\n",
    198                                 atomic_get(&call_cnt[i]), i, exp_call_cnt);
     198                            atomic_get(&call_cnt[i]), i, exp_call_cnt);
    199199                }
    200200        }
Note: See TracChangeset for help on using the changeset viewer.