Skip to content

Commit

Permalink
Use to-be-closed Lua variables in machine tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Jun 6, 2023
1 parent 84bea65 commit 5527c1e
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added static analysis for Lua code
- Added code formatter for Lua code
- Added support for to-be-closed variables for machine Lua API

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion src/tests/htif-console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ local function test(config, console_getchar_enable)
config.htif = {
console_getchar = console_getchar_enable,
}
local machine = cartesi.machine(config)
local machine <close> = cartesi.machine(config)
machine:run(math.maxinteger)

-- should be halted
Expand Down
2 changes: 1 addition & 1 deletion src/tests/htif-rollup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ end

local function test(config)
local pattern = "\xef\xcd\xab\x89\x67\x45\x23\x01"
local machine = cartesi.machine(config)
local machine <close> = cartesi.machine(config)

-- fill input with `pattern`
local rx = config.rollup.rx_buffer
Expand Down
2 changes: 1 addition & 1 deletion src/tests/htif-yield.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ local function test(config, yield_automatic_enable, yield_manual_enable)
yield_automatic = yield_automatic_enable,
yield_manual = yield_manual_enable,
}
local machine = cartesi.machine(config)
local machine <close> = cartesi.machine(config)
local break_reason
for _, v in ipairs(yields) do
if
Expand Down
2 changes: 1 addition & 1 deletion src/tests/log-with-mtime-transition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ local config = {
ram = { length = 1 << 20, image_filename = test_util.create_test_uarch_program() },
},
}
local machine = cartesi.machine(config)
local machine <close> = cartesi.machine(config)

local old_hash = machine:get_root_hash()
local access_log = machine:step_uarch({ proofs = true })
Expand Down
3 changes: 1 addition & 2 deletions src/tests/mcycle-overflow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ end

local function do_test(description, f)
io.write(" " .. description .. "...")
local machine = build_machine()
local machine <close> = build_machine()
f(machine)
machine:destroy()
print(" passed")
end

Expand Down
3 changes: 1 addition & 2 deletions src/tests/mtime-interrupt.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ end

local function do_test(description, f)
io.write(" " .. description .. "...")
local machine = build_machine()
local machine <close> = build_machine()
f(machine)
machine:destroy()
print(" passed")
end

Expand Down
3 changes: 1 addition & 2 deletions src/tests/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ end
function test_util.make_do_test(build_machine, type, config)
return function(description, f)
io.write(" " .. description .. "...\n")
local machine = build_machine(type, config)
local machine <close> = build_machine(type, config)
f(machine)
machine:destroy()
print("<<<<<<<<<<<<<<<< passed >>>>>>>>>>>>>>>")
end
end
Expand Down
6 changes: 2 additions & 4 deletions src/uarch-riscv-tests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ local function run(tests)
failed = false,
cycles = 0,
}
local machine = build_machine(ctx.ram_image)
local machine <close> = build_machine(ctx.ram_image)
io.write(ctx.ram_image, ": ")
machine:run_uarch(2 * ctx.expected_cycles)
check_test_result(machine, ctx, errors)
Expand All @@ -241,7 +241,6 @@ local function run(tests)
else
print("passed")
end
machine:destroy()
end
if error_count > 0 then
io.write(string.format("\nFAILED %d of %d tests:\n\n", error_count, #tests))
Expand Down Expand Up @@ -357,7 +356,7 @@ local function json_logs(tests)
accesses_count = 0,
}
contexts[#contexts + 1] = ctx
local machine = build_machine(ctx.ram_image)
local machine <close> = build_machine(ctx.ram_image)
io.write(ctx.ram_image, ": ")
run_machine_writing_json_logs(machine, ctx)
check_test_result(machine, ctx, errors)
Expand All @@ -367,7 +366,6 @@ local function json_logs(tests)
else
print("passed")
end
machine:destroy()
end
if error_count > 0 then
io.write(string.format("\nFAILED %d of %d tests:\n\n", error_count, #tests))
Expand Down
3 changes: 1 addition & 2 deletions tools/benchmarks/run-benchmarks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,12 @@ end
local function measure(exec_args)
local results = {}
for _ = 1, N_RUNS do
local machine = build_machine(exec_args)
local machine <close> = build_machine(exec_args)
local start = socket.gettime()
repeat
machine:run(MAX_MCYCLE)
until machine:read_iflags_H() or machine:read_mcycle() < MAX_MCYCLE
local elapsed = socket.gettime() - start
machine:destroy()
table.insert(results, elapsed)
end
return results
Expand Down

0 comments on commit 5527c1e

Please sign in to comment.