PreviousUpNext

15.4.1159  src/lib/std/src/pthread/io-wait-pthread-unit-test.pkg

## io-wait-pthread-unit-test.pkg
#
# Unit/regression test functionality for
#
#    src/lib/std/src/pthread/io-wait-pthread.pkg
#
# (The io_wait_pthread server offloads C select() waits on
# file descriptors from the main pthread pthread.)

# Compiled by:
#     src/lib/test/unit-tests.lib

# Run by:
#     src/lib/test/all-unit-tests.pkg


stipulate
    package pth =  pthread;                                                     # pthread                       is from   src/lib/std/src/pthread.pkg
    package iwp =  io_wait_pthread;                                             # io_wait_pthread               is from   src/lib/std/src/pthread/io-wait-pthread.pkg
    #
    sleep = makelib::scripting_globals::sleep;
herein

    package io_wait_pthread_unit_test {
        #
        include unit_test;                                                      # unit_test                     is from   src/lib/src/unit-test.pkg
 
        name =  "src/lib/std/src/pthread/io-wait-pthread-unit-test.pkg";
 
 
        fun verify_basic__is_running__operation ()
            =
            {   # Pretty minimal test:  :-)
                #
                assert( iwp::is_running () );
            };

        fun verify_basic__echo__operation ()
            =
            {   echoed_text = REF "";
                #
                iwp::echo  { what => "foo",  reply => (fn what = (echoed_text := what)) };
                #
                sleep 0.01;
                #
                assert( *echoed_text == "foo" );
            };

        fun verify_basic__stop__operation ()
            =
            {   iwp::stop  { who => "io-wait-pthread-unit-test",  reply => (fn _ = ()) };
                #
                sleep 0.01;
                #
                assert (not (iwp::is_running ()));
                #
                iwp::start  "io-wait-pthread-unit-test";
                sleep 0.01;
                #
                assert( iwp::is_running () );
            };

        fun run ()
            =
            {   printf "\nDoing %s:\n" name;   
                #
                iwp::start  "io-wait-pthread-unit-test";                                        # This will be a no-op if it is already running.
                #
                verify_basic__is_running__operation ();
                verify_basic__echo__operation ();
                verify_basic__stop__operation ();
                #
                summarize_unit_tests  name;
            };
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext