aboutsummaryrefslogtreecommitdiff
path: root/unit_tests
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-12-16 09:50:52 +0100
committerBenoit Germain <benoit.germain@ubisoft.com>2024-12-16 09:50:52 +0100
commitefd5318b2d9132996bf35a6af2e82706665890ff (patch)
treed92946126d43258b86a67c655353dba22f8982e0 /unit_tests
parent0740a54fe0f4d4264875ae1dc3334e33e27f4ff9 (diff)
downloadlanes-efd5318b2d9132996bf35a6af2e82706665890ff.tar.gz
lanes-efd5318b2d9132996bf35a6af2e82706665890ff.tar.bz2
lanes-efd5318b2d9132996bf35a6af2e82706665890ff.zip
Unit tests for thread name
Diffstat (limited to 'unit_tests')
-rw-r--r--unit_tests/lane_tests.cpp61
1 files changed, 56 insertions, 5 deletions
diff --git a/unit_tests/lane_tests.cpp b/unit_tests/lane_tests.cpp
index 14a327f..8b22fcd 100644
--- a/unit_tests/lane_tests.cpp
+++ b/unit_tests/lane_tests.cpp
@@ -104,17 +104,16 @@ TEST_F(LaneTests, UncooperativeShutdown)
104 lua_pushcfunction(S, _finallyCB); 104 lua_pushcfunction(S, _finallyCB);
105 lua_setglobal(S, "finallyCB"); 105 lua_setglobal(S, "finallyCB");
106 // start a lane that lasts a long time 106 // start a lane that lasts a long time
107 std::string_view const script{ 107 std::string_view const _script{
108 " lanes.finally(finallyCB)" 108 " lanes.finally(finallyCB)"
109 " print ('in Master')" 109 " g = lanes.gen('*',"
110 " f = lanes.gen('*',"
111 " {name = 'auto'}," 110 " {name = 'auto'},"
112 " function()" 111 " function()"
113 " for i = 1,1e37 do end" // no cooperative cancellation checks here! 112 " for i = 1,1e37 do end" // no cooperative cancellation checks here!
114 " end)" 113 " end)"
115 " f()" 114 " g()"
116 }; 115 };
117 ASSERT_EQ(S.doString(script), LuaError::OK) << S; 116 ASSERT_EQ(S.doString(_script), LuaError::OK) << S;
118 // close the state before the lane ends. 117 // close the state before the lane ends.
119 // since we don't wait at all, it is possible that the OS thread for the lane hasn't even started at that point 118 // since we don't wait at all, it is possible that the OS thread for the lane hasn't even started at that point
120 S.close(); 119 S.close();
@@ -124,6 +123,58 @@ TEST_F(LaneTests, UncooperativeShutdown)
124} 123}
125 124
126// ################################################################################################# 125// #################################################################################################
126
127TEST_F(LaneTests, DefaultThreadNameIsUnnamed)
128{
129 std::string_view const _script{
130 " g = lanes.gen('*',"
131 " function()"
132 " return lane_threadname()"
133 " end)"
134 " h = g()"
135 " local tn = h[1]"
136 " assert(tn == h:get_threadname())"
137 " return tn"
138 };
139 ASSERT_EQ(S.doStringAndRet(_script), "<unnamed>") << S;
140}
141
142// #################################################################################################
143
144TEST_F(LaneTests, UserThreadNameFromGenerator)
145{
146 std::string_view const _script{
147 " g = lanes.gen('*',"
148 " { name = 'user name'},"
149 " function()"
150 " return lane_threadname()"
151 " end)"
152 " h = g()"
153 " local tn = h[1]"
154 " assert(tn == h:get_threadname())"
155 " return tn"
156 };
157 ASSERT_EQ(S.doStringAndRet(_script), "user name") << S;
158}
159
160// #################################################################################################
161
162TEST_F(LaneTests, UserThreadNameFromInside)
163{
164 std::string_view const _script{
165 " g = lanes.gen('*',"
166 " function()"
167 " lane_threadname('user name')"
168 " return true"
169 " end)"
170 " h = g()"
171 " h:join()"
172 " return h:get_threadname()"
173 };
174 ASSERT_EQ(S.doStringAndRet(_script), "user name") << S;
175}
176
177// #################################################################################################
127// ################################################################################################# 178// #################################################################################################
128 179
129class LaneCancel : public ::testing::Test 180class LaneCancel : public ::testing::Test