2019-06-27 06:29:09 +00:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
2019-06-27 06:29:09 +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.
|
2017-11-03 08:10:52 +00:00
|
|
|
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-11-03 16:26:55 +00:00
|
|
|
|
2017-10-31 15:14:12 +00:00
|
|
|
sg addSemaphore: s1.
|
|
|
|
sg addSemaphore: s2.
|
|
|
|
sg addSemaphore: s3.
|
|
|
|
|
2018-05-18 08:10:16 +00:00
|
|
|
s1 signalOnInput: 0.
|
2019-06-27 06:29:09 +00:00
|
|
|
s2 signalOnInput: 0. // this should raise an exception as the same file descriptor is added to a different semaphore
|
2018-05-18 08:10:16 +00:00
|
|
|
s3 signalOnInput: 0.
|
2017-10-31 15:14:12 +00:00
|
|
|
|
|
|
|
[ sg wait. ] fork.
|
|
|
|
[ sg wait. ] fork.
|
|
|
|
[ sg wait. ] fork.
|
|
|
|
|
2017-12-26 15:55:06 +00:00
|
|
|
System sleepForSecs: 1.
|
2017-10-31 15:14:12 +00:00
|
|
|
sg wait.
|
2017-11-03 08:10:52 +00:00
|
|
|
sg removeSemaphore: s1.
|
2019-06-27 08:06:33 +00:00
|
|
|
"********** 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
|
|
|
|
2019-06-27 07:43:17 +00:00
|
|
|
tc := ##(
|
2019-06-27 06:29:09 +00:00
|
|
|
// 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.
|
2019-06-27 08:06:33 +00:00
|
|
|
System log(System.Log.INFO, idx asString, (if (tb value) { " PASS" } else { " FAIL" }), "\n").
|
2017-12-25 18:35:23 +00:00
|
|
|
].
|
2019-05-30 15:44:24 +00:00
|
|
|
|
2019-06-27 08:06:33 +00:00
|
|
|
"********** END OF MAIN PROGRAM *************" dump.
|
2016-03-28 13:27:03 +00:00
|
|
|
}
|
|
|
|
}
|