File: 23-eventfd.lua

package info (click to toggle)
lua-cqueues 20200726-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,848 kB
  • sloc: ansic: 23,623; sh: 2,984; makefile: 24
file content (38 lines) | stat: -rwxr-xr-x 797 bytes parent folder | download | duplicates (4)
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
#!/bin/sh
_=[[
	. "${0%%/*}/regress.sh"
	exec runlua "$0" "$@"
]]
--
-- Simple test of controller alerts to check whether our eventfd support
-- works and didn't break anything else. A controller triggers its alert
-- event when adding a new coroutine and it's not currently looping.
--
require"regress".export".*"

local main = cqueues.new()
local sub = cqueues.new()
local sub_islooping = false
local sub_alerted = false

assert(main:wrap(function()
	sub_islooping = true
	assert(sub:loop())
end))

assert(main:step(0))
assert(sub_islooping)

assert(main:wrap(function ()
	assert(not sub_alerted)

	-- this should cause the main loop to resume the sub loop
	assert(sub:wrap(function()
		sub_alerted = true
	end))
end))

assert(main:loop(3))
check(sub_alerted, "sub loop never woke up")

say"OK"