Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 36 additions & 32 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
name: test

on: [push]
on:
push:
paths-ignore:
- '**.md'
- 'LICENSE'

jobs:
luacheck:
runs-on: ubuntu-latest
container:
image: ghcr.io/mah0x211/lua-ci:latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Setup Lua
uses: leafo/gh-actions-lua@v8.0.0
-
name: Setup Luarocks
uses: leafo/gh-actions-luarocks@v4
-
name: Install Tools
run: luarocks install luacheck
Expand All @@ -24,50 +24,54 @@ jobs:
luacheck .

test:
needs: luacheck
permissions:
id-token: write
runs-on: ubuntu-latest
container:
image: ghcr.io/mah0x211/lua-ci:latest
strategy:
matrix:
lua-version:
- "5.1"
- "5.2"
- "5.3"
- "5.4"
- "luajit-2.0.5"
- "luajit-openresty"
- "5.1.:latest"
- "5.2.:latest"
- "5.3.:latest"
- "5.4.:latest"
- "lj-v2.1:latest"
steps:
-
name: Switch Lua Version
run: |
lenv -g use ${{ matrix.lua-version }}
lua -v || true
-
name: Checkout
uses: actions/checkout@v2
with:
submodules: 'true'
-
name: Setup Lua ${{ matrix.lua-version }}
uses: leafo/gh-actions-lua@v8.0.0
with:
luaVersion: ${{ matrix.lua-version }}
-
name: Setup Luarocks
uses: leafo/gh-actions-luarocks@v4
name: Install
run: |
ACT_COVERAGE=1 luarocks make
-
name: Install Test Tools
name: Install Tools
run: |
luarocks install testcase
luarocks install assert
luarocks install errno
luarocks install llsocket
luarocks install signal
luarocks install luacov
-
name: Install
run: |
luarocks make
-
name: Run Test
run: |
testcase --coverage ./test/
-
name: Upload lua coverage to Codecov
uses: codecov/codecov-action@v2
name: Generate coverage reports
run: |
sh ./covgen.sh
-
name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
files: ./luacov.report.out
use_oidc: true
disable_search: true
files: ./luacov.report.out,./coverage/lcov.info
flags: unittests

2 changes: 1 addition & 1 deletion act.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ local function pwaitpid(sec, wpid, ...)
end

while true do
local res, err, again = waitpid(wpid, 'nohang', ...)
local res, err, again = waitpid(wpid, nil, 'nohang', ...)
if res then
return res
elseif not again then
Expand Down
7 changes: 7 additions & 0 deletions covgen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env sh

set -ex

mkdir -p ./coverage
lcov -c -d ./src -o coverage/lcov.info.all
lcov -r coverage/lcov.info.all '*/include/*' -o coverage/lcov.info
55 changes: 41 additions & 14 deletions rockspecs/act-scm-1.rockspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
rockspec_format = "3.0"
package = "act"
version = "scm-1"
source = {
Expand All @@ -11,24 +12,45 @@ description = {
}
dependencies = {
"lua >= 5.1",
"lauxhlib >= 0.5",
"denque >= 0.5",
"fork >= 0.2",
"metamodule >= 0.4",
"minheap >= 0.2",
"reco >= 1.6",
"epoll >= 0.5.0",
"kqueue >= 0.6.0",
"time-clock >= 0.4.0",
"time-sleep >= 0.2.1",
"waitpid >= 0.1.0",
"lauxhlib >= 0.6.3",
"denque >= 0.5.2",
"fork >= 0.4.2",
"metamodule >= 0.5.1",
"minheap >= 0.2.0",
"reco >= 1.6.1",
"epoll >= 0.6.0",
"kqueue >= 0.7.0",
"time-clock >= 0.5.2",
"time-sleep >= 0.2.3",
"waitpid >= 0.3.4",
}
build_dependencies = {
"luarocks-build-hooks >= 0.8.0",
}
build = {
type = "builtin",
type = "hooks",
before_build = {
"$(extra-vars)",
},
extra_variables = {
CFLAGS = "-Wall -Wno-trigraphs -Wmissing-field-initializers -Wreturn-type -Wmissing-braces -Wparentheses -Wno-switch -Wunused-function -Wunused-label -Wunused-parameter -Wunused-variable -Wunused-value -Wuninitialized -Wunknown-pragmas -Wshadow -Wsign-compare",
},
conditional_variables = {
ACT_COVERAGE = {
CFLAGS = "--coverage",
LIBFLAG = "--coverage",
},
},
modules = {
act = "act.lua",
["act.aux"] = "lib/aux.lua",
["act.bitset"] = "src/bitset.c",
["act.bitset"] = {
sources = "src/bitset.c",
incdirs = {
"src",
"$(DEP_LAUXHLIB_INCDIR)",
},
},
["act.callee"] = "lib/callee.lua",
["act.context"] = "lib/context.lua",
["act.coro"] = "lib/coro.lua",
Expand All @@ -42,6 +64,11 @@ build = {
["act.poller"] = "lib/poller.lua",
["act.pool"] = "lib/pool.lua",
["act.runq"] = "lib/runq.lua",
["act.stack"] = "src/stack.c",
["act.stack"] = {
sources = "src/stack.c",
incdirs = {
"$(DEP_LAUXHLIB_INCDIR)",
},
},
},
}
6 changes: 6 additions & 0 deletions src/bitset.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@
* IN THE SOFTWARE.
*/

// project
#include "bitset.h"
// depend
#include "lauxhlib.h"
// lua
#include <lauxlib.h>
// system
#include <string.h>

#define MODULE_MT "act.bitset"

Expand Down
3 changes: 2 additions & 1 deletion src/getcpus.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
// lua
#include <lua.h>
// system
#include <unistd.h>

static int getcpus_lua(lua_State *L)
{
Expand Down
5 changes: 3 additions & 2 deletions src/ignsigpipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
* this code copied from lua-nosigpipe
*/

#include <signal.h>
// lualib
// lua
#include <lauxlib.h>
// system
#include <signal.h>

LUALIB_API int luaopen_act_ignsigpipe(lua_State *L)
{
Expand Down
4 changes: 3 additions & 1 deletion src/stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
* IN THE SOFTWARE.
*/

// depend
#include "lauxhlib.h"
// lua
#include <lauxlib.h>

#define MODULE_MT "act.stack"

Expand Down Expand Up @@ -89,7 +92,6 @@ static int set_lua(lua_State *L)
{
int argc = lua_gettop(L) - 1;
act_stack_t *s = luaL_checkudata(L, 1, MODULE_MT);
lua_Integer n = 0;

// clear arguments
lua_settop(s->L, 0);
Expand Down
5 changes: 2 additions & 3 deletions test/act_fork_waitpid_test.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local with_luacov = require('luacov').with_luacov
local testcase = require('testcase')
local getpid = require('testcase.getpid')
local errno = require('errno')
local act = require('act')
local gettime = require('time.clock').gettime

Expand Down Expand Up @@ -123,11 +122,11 @@ function testcase.waitpid()
return
end

-- test that return error if no child process exists
-- test that return all nil if no child process exists
assert(act.run(with_luacov(function()
local res, err, timeout = act.waitpid()
assert.is_nil(res)
assert.equal(err.type, errno.ECHILD)
assert.is_nil(err)
assert.is_nil(timeout)
end)))

Expand Down
98 changes: 98 additions & 0 deletions test/bitset_test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
local testcase = require('testcase')
local assert = require('assert')
local bitset = require('act.bitset')

function testcase.new_and_tostring()
local bs = bitset()
assert.match(tostring(bs), 'act.bitset: 0x', false)
end

function testcase.get_set_unset()
local bs = bitset()
-- initial value is 0
assert.is_false(bs:get(0))
assert.is_false(bs:get(100))
-- set then get returns 1
assert.is_true(bs:set(10))
assert.is_true(bs:get(10))
-- unset then get returns 0
assert.is_true(bs:unset(10))
assert.is_false(bs:get(10))
end

function testcase.set_resizes_when_pos_exceeds_capacity()
local bs = bitset()
-- initial capacity is 4096 bits, set beyond it triggers resize
assert.is_true(bs:set(8192))
assert.is_true(bs:get(8192))
assert.is_false(bs:get(8000))
end

function testcase.get_out_of_range_returns_error()
local bs = bitset()
-- get does not resize; out-of-range returns nil + ERANGE message
local v, err, errno = bs:get(1000000)
assert.is_nil(v)
assert.is_string(err)
assert.greater(errno, 0)
end

function testcase.unset_out_of_range_returns_error()
local bs = bitset()
-- unset does not resize; out-of-range returns nil + ERANGE message
local ok, err, errno = bs:unset(1000000)
assert.is_nil(ok)
assert.is_string(err)
assert.greater(errno, 0)
end

function testcase.ffz_empty_partial_full()
local bs = bitset()
-- empty: first zero is position 0
assert.equal(bs:ffz(), 0)
-- after setting bit 0, first zero is 1
bs:set(0)
assert.equal(bs:ffz(), 1)
-- after setting bit 1, first zero is 2
bs:set(1)
assert.equal(bs:ffz(), 2)
end

function testcase.ffz_returns_capacity_when_full()
local bs = bitset()
for pos = 0, 4095 do
bs:set(pos)
end
-- when bitset is fully set, ffz reports nbit (no zero bit found)
assert.equal(bs:ffz(), 4096)
end

function testcase.add_returns_consecutive_positions()
local bs = bitset()
assert.equal(bs:add(), 0)
assert.equal(bs:add(), 1)
assert.equal(bs:add(), 2)
bs:unset(1)
-- next add reuses freed position
assert.equal(bs:add(), 1)
assert.equal(bs:add(), 3)
end

function testcase.add_grows_beyond_initial_capacity()
local bs = bitset()
-- exhaust initial capacity
for _ = 0, 4095 do
bs:add()
end
-- next add must trigger resize and succeed
assert.equal(bs:add(), 4096)
assert.is_true(bs:get(4096))
end

function testcase.gc_cleanup()
local bs = bitset()
bs:set(0)
bs = nil -- luacheck: ignore 311
collectgarbage('collect')
collectgarbage('collect')
end
Loading
Loading