PreviousUpNext

15.4.1089  src/lib/std/src/hostthread/cpu-bound-task-hostthreads-unit-test.pkg

## cpu-bound-task-hostthreads-unit-test.pkg
#
# Unit/regression test functionality for
#
#    src/lib/std/src/hostthread/cpu-bound-task-hostthreads.pkg
#
# (The cpu_bound_task_hostthreads server offloads cpu-intensive
# tasks 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 cpu =  cpu_bound_task_hostthreads;                                  # cpu_bound_task_hostthreads    is from   src/lib/std/src/hostthread/cpu-bound-task-hostthreads.pkg
    #
    sleep = makelib::scripting_globals::sleep;
herein

    package cpu_bound_task_hostthreads_unit_test {
        #
        include package   unit_test;                                            # unit_test                     is from   src/lib/src/unit-test.pkg
 
        name =  "src/lib/std/src/hostthread/cpu-bound-task-hostthreads-unit-test.pkg";
 
 
        fun verify_basic__servercount__operation ()
            =
            {   # Pretty minimal test:  :-)
                #
                assert(  cpu::get_count_of_live_hostthreads () >= 0  );
            };

        fun verify_basic__start__operation ()
            =
            {
                before_servercount
                    =
                    cpu::get_count_of_live_hostthreads ();

                cpu::change_number_of_server_hostthreads_to "cpu-bound-task-hostthreads-unit-test" (before_servercount + 2);
#               count2 =  cpu::start_one_server_hostthread  "cycleserver-hostthread-unit-test";
#               count3 =  cpu::start_one_server_hostthread  "cycleserver-hostthread-unit-test";
                #
                sleep 0.01;
                #
                after_servercount
                    =
                    cpu::get_count_of_live_hostthreads ();

                assert (after_servercount == before_servercount + 2);
            };

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

        fun verify_basic__do__operation ()
            =
            {   result1 = REF 0;
                result2 = REF 0;
                #
                cpu::do  (\\ () =  result1 := 1);
                cpu::do  (\\ () =  result2 := 2);
                #
                sleep 0.01;
                #
                assert( *result1 == 1 );
                assert( *result2 == 2 );
            };

        fun verify_basic__stop__operation ()
            =
            {
                before_servercount
                    =
                    cpu::get_count_of_live_hostthreads ();

                cpu::change_number_of_server_hostthreads_to "cpu-bound-task-hostthreads-unit-test" (before_servercount - 2);

#               cpu::stop_one_server_hostthread  { per_who => "cycleserver-hostthread-unit-test",  reply => (\\ _ = ()) };
#               cpu::stop_one_server_hostthread  { per_who => "cycleserver-hostthread-unit-test",  reply => (\\ _ = ()) };
                #
                sleep 0.01;
                #
                after_servercount
                    =
                    cpu::get_count_of_live_hostthreads ();

                assert (after_servercount == before_servercount - 2);
            };

        fun run ()
            =
            {   printf "\nDoing %s:\n" name;   
                #
                verify_basic__servercount__operation ();
                verify_basic__start__operation ();
                verify_basic__echo__operation ();
                verify_basic__do__operation ();
                verify_basic__stop__operation ();
                #
                summarize_unit_tests  name;
            };
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext