Changeset 9f8745c5 in mainline


Ignore:
Timestamp:
2012-07-10T18:07:34Z (12 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b23c88e
Parents:
5b6c033
Message:

workq: Moved almost all tests to a single test entry function.

Location:
kernel
Files:
2 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • kernel/Makefile

    r5b6c033 r9f8745c5  
    305305                test/synch/semaphore1.c \
    306306                test/synch/semaphore2.c \
    307                 test/synch/rcu1.c \
    308                 test/synch/workqueue1.c \
    309307                test/synch/workqueue2.c \
    310308                test/synch/workqueue3.c \
     309                test/synch/rcu1.c \
    311310                test/print/print1.c \
    312311                test/print/print2.c \
  • kernel/generic/include/synch/workqueue.h

    r5b6c033 r9f8745c5  
     1/*
     2 * Copyright (c) 2012 Adam Hraska
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
     29/** @addtogroup generic
     30 * @{
     31 */
     32/** @file
     33 */
    134
    235#ifndef KERN_WORKQUEUE_H_
     
    4679
    4780#endif /* KERN_WORKQUEUE_H_ */
     81
     82/** @}
     83 */
  • kernel/generic/src/synch/workqueue.c

    r5b6c033 r9f8745c5  
     1/*
     2 * Copyright (c) 2012 Adam Hraska
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
     29/** @addtogroup generic
     30 * @{
     31 */
     32
     33/**
     34 * @file
     35 * @brief Work queue/thread pool that automatically adjusts its size
     36 *        depending on the current load. Queued work functions may sleep..
     37 */
     38
    139#include <synch/workqueue.h>
    240#include <synch/spinlock.h>
     
    934972#endif
    935973}
     974
     975/** @}
     976 */
  • kernel/test/synch/workq-test-core.h

    r5b6c033 r9f8745c5  
    203203                return NULL;
    204204        else {
    205                 return "Failed to invoke the expected number of calls.";
    206         }
    207 }
     205                return "Failed to invoke the expected number of calls.\n";
     206        }
     207}
  • kernel/test/synch/workqueue2.c

    r5b6c033 r9f8745c5  
    4747
    4848
     49/*-------------------------------------------------------------------*/
     50
     51static work_t basic_work;
     52static int basic_done = 0;
     53
     54static void basic_test_work(work_t *work_item)
     55{
     56        basic_done = 1;
     57        TPRINTF("basic_test_work()");
     58}
     59
     60
     61static void basic_test(void)
     62{
     63        TPRINTF("Issue a single work item.\n");
     64        basic_done = 0;
     65        workq_global_enqueue(&basic_work, basic_test_work);
     66       
     67        while (!basic_done) {
     68                TPRINTF(".");
     69                thread_sleep(1);
     70        }
     71
     72        TPRINTF("\nBasic test done\n");
     73}
     74
     75/*-------------------------------------------------------------------*/
     76
     77
    4978struct work_queue *workq = NULL;
    5079
     
    5382        return workq_enqueue(workq, work_item, func);
    5483}
     84/*-------------------------------------------------------------------*/
    5585
    5686
    57 
    58 const char *test_workqueue2(void)
     87static const char *test_custom_workq_impl(bool stop, const char *qname)
    5988{
    60         workq = workq_create("test-workq");
     89        workq = workq_create(qname);
    6190       
    6291        if (!workq) {
    63                 return "Failed to create a work queue.";
     92                return "Failed to create a work queue.\n";
    6493        }
    6594       
    66         const char *ret = run_workq_core(false);
     95        const char *ret = run_workq_core(stop);
    6796       
    6897        TPRINTF("Stopping work queue...\n");
     
    71100        TPRINTF("Destroying work queue...\n");
    72101        workq_destroy(workq);
    73 
    74102        return ret;
    75103}
    76104
     105static const char *test_custom_workq(void)
     106{
     107        TPRINTF("Stress testing a custom queue.\n");
     108        return test_custom_workq_impl(false, "test-workq");
     109}
    77110
    78 const char *test_workqueue2stop(void)
     111
     112static const char *test_custom_workq_stop(void)
    79113{
    80         workq = workq_create("test-workq");
     114        TPRINTF("Stress testing a custom queue. Stops prematurely. "
     115                "Errors are expected.\n");
     116        test_custom_workq_impl(true, "test-workq-stop");
     117        /* Errors are expected. */
     118        return 0;
     119}
     120
     121
     122const char *test_workqueue_all(void)
     123{
     124        const char *err = 0;
     125        const char *res;
    81126       
    82         if (!workq) {
    83                 return "Failed to create a work queue.";
     127        basic_test();
     128       
     129        res = test_custom_workq();
     130        if (res) {
     131                TPRINTF(res);
     132                err = res;
    84133        }
    85134       
    86         const char *ret = run_workq_core(true);
     135        res = test_custom_workq_stop();
     136        if (res) {
     137                TPRINTF(res);
     138                err = res;
     139        }
    87140       
    88         TPRINTF("Stopping work queue...\n");
    89         workq_stop(workq);
    90        
    91         TPRINTF("Destroying work queue...\n");
    92         workq_destroy(workq);
     141        res = test_workqueue3();
     142        if (res) {
     143                TPRINTF(res);
     144                err = res;
     145        }
    93146
    94         return ret;
     147        return err;
    95148}
    96 
  • kernel/test/synch/workqueue2.def

    r5b6c033 r9f8745c5  
    11{
    2         "workqueue2",
    3         "Separate work queue test",
    4         &test_workqueue2,
     2        "workqueue",
     3        "Separate and system work queue stress test",
     4        &test_workqueue_all,
    55        true
    66},
    7 {
    8         "workqueue2stop",
    9         "Separate work queue test, stops early",
    10         &test_workqueue2stop,
    11         true
    12 },
  • kernel/test/synch/workqueue3.c

    r5b6c033 r9f8745c5  
    5757{
    5858        const char *err = 0;
    59        
     59        TPRINTF("Stress testing system queue.\n");
    6060        TPRINTF("First run:\n");
    6161        err = run_workq_core(exit_early);
  • kernel/test/synch/workqueue3.def

    r5b6c033 r9f8745c5  
    1 {
    2         "workqueue3",
    3         "Global work queue test",
    4         &test_workqueue3,
    5         true
    6 },
    71{
    82        "workqueue3quit",
  • kernel/test/test.c

    r5b6c033 r9f8745c5  
    5151#include <synch/semaphore2.def>
    5252#include <synch/rcu1.def>
    53 #include <synch/workqueue1.def>
    5453#include <synch/workqueue2.def>
    5554#include <synch/workqueue3.def>
  • kernel/test/test.h

    r5b6c033 r9f8745c5  
    7676extern const char *test_thread1(void);
    7777extern const char *test_smpcall1(void);
    78 extern const char *test_workqueue1(void);
    79 extern const char *test_workqueue2(void);
    80 extern const char *test_workqueue2stop(void);
     78extern const char *test_workqueue_all(void);
    8179extern const char *test_workqueue3(void);
    8280extern const char *test_workqueue3quit(void);
Note: See TracChangeset for help on using the changeset viewer.