|author||Neels Hofmeyr <email@example.com>||2017-09-14 01:31:41 +0200|
|committer||Neels Hofmeyr <firstname.lastname@example.org>||2017-09-14 01:52:32 +0200|
fix util.py/FileLock and lock_test
Do not pass os.O_TRUNC to open(), that immediately empties out the lock file. Fix lock_test to be able to catch this error. So far things were happening too fast to notice it. Caught by running 'make check' on a main unit APU that has different timing behavior. Change-Id: I872a3d2548ac84097ac7acf13cb12c36822e076e
Diffstat (limited to 'selftest')
3 files changed, 41 insertions, 1 deletions
diff --git a/selftest/lock_test.ok b/selftest/lock_test.ok
index 604767b..011a89c 100644
@@ -1,4 +1,14 @@
+launch a program that locks a given file, it will create $dir/lock_test
+wait until this lock_test lock file was created by program
+expecting the lock file to reflect "long name"
launched first, locked by: 'long name'
+launching second program, should find the lock intact and wait
launched second, locked by: 'long name'
+drop the first lock, $f1 removal signals the first process to stop locking
+wait for first program to carry out the lock release
+now expecting second program to lock
waited, locked by: 'shorter'
+release the second program also
+expecting the lock to be gone
waited more, locked by: ''
diff --git a/selftest/lock_test.sh b/selftest/lock_test.sh
index 049c4d9..4f3f7ad 100755
@@ -1,4 +1,6 @@
+echo 'creating files'
@@ -7,21 +9,45 @@ n2="shorter"
+echo 'launch a program that locks a given file, it will create $dir/lock_test'
python3 ./lock_test_help.py "$dir" "$n1" &
+echo 'wait until this lock_test lock file was created by program'
while [ ! -f "$dir/lock_test" ]; do
+echo 'expecting the lock file to reflect "long name"'
echo "launched first, locked by: '$(cat "$dir/lock_test")'"
+echo 'launching second program, should find the lock intact and wait'
python3 ./lock_test_help.py "$dir" "$n2" &
+while [ ! -f "$f2.ready" ]; do
+ sleep .1
echo "launched second, locked by: '$(cat "$dir/lock_test")'"
+echo 'drop the first lock, $f1 removal signals the first process to stop locking'
+echo 'wait for first program to carry out the lock release'
while [ ! -f "$f1.done" ]; do
+echo 'now expecting second program to lock'
echo "waited, locked by: '$(cat "$dir/lock_test")'"
+echo 'release the second program also'
while [ ! -f "$f2.done" ]; do
+echo 'expecting the lock to be gone'
echo "waited more, locked by: '$(cat "$dir/lock_test")'"
rm -rf "$dir"
diff --git a/selftest/lock_test_help.py b/selftest/lock_test_help.py
index bdf7c64..f4e1f9b 100644
@@ -8,11 +8,15 @@ from osmo_gsm_tester.util import FileLock, touch_file
testdir, name = sys.argv[1:]
stop_signalling_file = os.path.join(testdir, name)
+if not os.path.isfile(stop_signalling_file):
+ print('expected a stop-file %r' % stop_signalling_file)
lockfile_path = os.path.join(testdir, 'lock_test')
fl = FileLock(lockfile_path, name)
+touch_file(stop_signalling_file + '.ready')