moo/kernel/test-004.moo

76 lines
1.4 KiB
Smalltalk
Raw Normal View History

//
// TEST CASES for basic methods
//
2016-03-28 13:27:03 +00:00
2017-01-09 12:52:37 +00:00
#include 'Moo.moo'.
2016-03-28 13:27:03 +00:00
////////////////////////////////////////////////////////////////#
// MAIN
////////////////////////////////////////////////////////////////#
2016-03-28 13:27:03 +00:00
2017-10-31 15:08:58 +00:00
class MyObject(Object)
2016-03-28 13:27:03 +00:00
{
2017-10-31 15:14:12 +00:00
var(#class) t1 := 20.
2016-03-28 13:27:03 +00:00
2017-10-31 15:08:58 +00:00
method(#class) test_terminate
2016-03-28 13:27:03 +00:00
{
2017-10-31 15:08:58 +00:00
| a s |
s := Semaphore new.
2017-10-31 15:14:12 +00:00
a := [ self.t1 := self.t1 * 9.
2017-10-31 15:08:58 +00:00
s signal.
Processor activeProcess terminate.
2017-10-31 15:14:12 +00:00
self.t1 := self.t1 + 20 ] fork.
s wait.
2017-10-31 15:14:12 +00:00
^self.t1
}
method(#class) test_sg
{
| sg s1 s2 s3 |
s1 := Semaphore new.
s2 := Semaphore new.
s3 := Semaphore new.
sg := SemaphoreGroup new.
2017-10-31 15:14:12 +00:00
sg addSemaphore: s1.
sg addSemaphore: s2.
sg addSemaphore: s3.
s1 signalOnInput: 0.
s2 signalOnInput: 0. // this should raise an exception as the same file descriptor is added to a different semaphore
s3 signalOnInput: 0.
2017-10-31 15:14:12 +00:00
[ sg wait. ] fork.
[ sg wait. ] fork.
[ sg wait. ] fork.
System sleepForSecs: 1.
2017-10-31 15:14:12 +00:00
sg wait.
sg removeSemaphore: s1.
"********** END OF TESTER *************" dump.
2016-03-28 13:27:03 +00:00
}
2017-10-31 15:08:58 +00:00
method(#class) main
2016-03-28 13:27:03 +00:00
{
2017-10-31 15:08:58 +00:00
| tc limit |
2016-03-28 13:27:03 +00:00
tc := ##(
// 0 - 4
2017-10-31 15:14:12 +00:00
[self test_terminate == 180],
[self test_sg == nil]
2017-10-31 15:08:58 +00:00
).
2016-03-28 13:27:03 +00:00
2017-10-31 15:08:58 +00:00
limit := tc size.
2016-03-28 13:27:03 +00:00
2017-10-31 15:08:58 +00:00
0 priorTo: limit by: 1 do: [ :idx |
| tb |
tb := tc at: idx.
System log(System.Log.INFO, idx asString, (if (tb value) { " PASS" } else { " FAIL" }), "\n").
2017-12-25 18:35:23 +00:00
].
"********** END OF MAIN PROGRAM *************" dump.
2016-03-28 13:27:03 +00:00
}
}