PreviousUpNext

15.4.1093  src/lib/std/src/hostthread/io-wait-hostthread-unit-test.pkg

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

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

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


stipulate
#   package hth =  hostthread;                                                                                                  # hostthread                    is from   src/lib/std/src/hostthread.pkg
    package iwp =  io_wait_hostthread;                                                                                          # io_wait_hostthread            is from   src/lib/std/src/hostthread/io-wait-hostthread.pkg
    #
    sleep = makelib::scripting_globals::sleep;
herein

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

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

        fun verify_basic__stop__operation ()
            =
            {   iwp::stop_server_hostthread_if_running  { per_who => "io-wait-hostthread-unit-test",  reply => (\\ _ = ()) };
                #
                sleep 0.01;
                #
                assert (not (iwp::is_running ()));
                #
                iwp::start_server_hostthread_if_not_running  "io-wait-hostthread-unit-test";
                sleep 0.01;
                #
                assert( iwp::is_running () );
            };

        fun run ()
            =
            {   printf "\nDoing %s:\n" name;
                #
                iwp::start_server_hostthread_if_not_running  "io-wait-hostthread-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