File: Thread.cpp

package info (click to toggle)
storm-lang 0.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,028 kB
  • sloc: ansic: 261,471; cpp: 140,432; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (62 lines) | stat: -rw-r--r-- 2,589 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "stdafx.h"
#include "Fn.h"
#include "Compiler/Debug.h"
#include "Compiler/Exception.h"

BEGIN_TEST(BSThread, BS) {
	using namespace storm::debug;

	Engine &e = gEngine();

	Thread *thread = runFn<Thread *>(S("tests.bs.getThread"));
	CHECK_NEQ(thread, storm::Compiler::thread(e));
	thread = runFn<Thread *>(S("tests.bs.getCompilerThread"));
	CHECK_EQ(thread, storm::Compiler::thread(e));

	CHECK_EQ(runFn<Int>(S("tests.bs.postInt")), 9);

	// Check so that we keep reference counting correct.
	DbgVal::clear();
	CHECK_EQ(runFn<Int>(S("tests.bs.postDbgVal")), 18);
	CHECK(DbgVal::clear());

	// Basic thread tests.
	CHECK_EQ(runFn<Int>(S("tests.bs.postObject")), 13);
	CHECK_EQ(runFn<Int>(S("tests.bs.postVal")), 33);
	CHECK_EQ(runFn<Int>(S("tests.bs.postMaybeVal")), 33);
	CHECK_EQ(runFn<Int>(S("tests.bs.threadObj")), 20);
	CHECK_EQ(runFn<Int>(S("tests.bs.threadActor")), 20);
	CHECK_EQ(runFn<Int>(S("tests.bs.actorObj")), 31);
	CHECK_EQ(runFn<Int>(S("tests.bs.actorDerObj")), 22);

	// Future tests.
	CHECK_EQ(runFn<Int>(S("tests.bs.basicFuture")), 8);
	CHECK_EQ(runFn<Int>(S("tests.bs.valueFuture")), 8);
	CHECK_EQ(runFn<Int>(S("tests.bs.intFuture")), 22);
	CHECK_RUNS(runFn<void>(S("tests.bs.noResultFuture")));

	// Check 'spawn'.
	CHECK_EQ(runFn<Int>(S("tests.bs.asyncPostInt")), 9);
	CHECK_EQ(runFn<Int>(S("tests.bs.asyncPostObject")), 13);
	CHECK_EQ(runFn<Int>(S("tests.bs.asyncPostObject2")), 13);
	CHECK_EQ(runFn<Int>(S("tests.bs.asyncPostVal")), 33);
	CHECK_RUNS(runFn<void>(S("tests.bs.spawnVoid")));

	// Check 'spawn' to the same thread. This should *not* cause any deep copies (we don't
	// differentiate between classes and values here - we know that works properly from earlier tests).
	CHECK_EQ(runFn<Int>(S("tests.bs.asyncPostSame")), 4);
	CHECK_EQ(runFn<Int>(S("tests.bs.asyncReturnSame")), 4);
	CHECK_EQ(runFn<Int>(S("tests.bs.asyncPostSameThread")), 4);

	// Check variable accesses in other threads.
	CHECK_EQ(runFn<Int>(S("tests.bs.threadVarAccess")), 6); // 1 copy, 1 deep copy. Starts at 4.
	CHECK_ERROR(runFn<void>(S("tests.bs.threadVarAssign")), SyntaxError);

	// Check so that we don't mistake variables named "this" for the real thing.
	CHECK_EQ(runFn<Int>(S("tests.bs.defaultThis")), 4); // Standard behavior, no copies.
	CHECK_EQ(runFn<Int>(S("tests.bs.customThis")), 6); // 1 copy + 1 deep copy. Starts at 4.

	// Check the semantics of the "spawn(...)" syntax:
	CHECK_EQ(runFn<Int>(S("tests.bs.asyncPostExplicit")), 6); // 1 copy + 1 deep copy, starts at 4.
	CHECK_ERROR(runFn<void>(S("tests.bs.asyncPostExplictError")), SyntaxError);
} END_TEST