diff --git a/tests/Makefile b/tests/Makefile index feab62807..f691ef4a2 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -85,7 +85,7 @@ RUN_ARCH_TEST = $(LUA) $(abspath ./lua/run-rv64i-arch-test.lua) CARTESI_IMAGES = $(CARTESI_IMAGES_PATH)/linux.bin STYLUA=stylua -STYLUA_FLAGS=--indent-type Spaces --collapse-simple-statement Always +STYLUA_FLAGS=--indent-type Spaces build-tests-all: misc build-tests-machine-with-toolchain build-tests-uarch-with-toolchain images $(CARTESI_CMIO_PATH) diff --git a/tests/lua/cartesi-machine-tests.lua b/tests/lua/cartesi-machine-tests.lua index bc4234f7d..74479f79f 100755 --- a/tests/lua/cartesi-machine-tests.lua +++ b/tests/lua/cartesi-machine-tests.lua @@ -418,21 +418,27 @@ local options = { { "^%-%-h$", function(all) - if not all then return false end + if not all then + return false + end help() end, }, { "^%-%-help$", function(all) - if not all then return false end + if not all then + return false + end help() end, }, { "^%-%-remote%-address%=(.*)$", function(o) - if not o or #o < 1 then return false end + if not o or #o < 1 then + return false + end remote_address = o return true end, @@ -440,7 +446,9 @@ local options = { { "^%-%-output%=(.*)$", function(o) - if not o or #o < 1 then return false end + if not o or #o < 1 then + return false + end output = o return true end, @@ -448,7 +456,9 @@ local options = { { "^%-%-json%-test%-list$", function(all) - if not all then return false end + if not all then + return false + end json_list = true return true end, @@ -456,7 +466,9 @@ local options = { { "^%-%-test%-path%=(.*)$", function(o) - if not o or #o < 1 then return false end + if not o or #o < 1 then + return false + end test_path = o return true end, @@ -464,7 +476,9 @@ local options = { { "^%-%-test%=(.*)$", function(o) - if not o or #o < 1 then return false end + if not o or #o < 1 then + return false + end test_pattern = o return true end, @@ -472,7 +486,9 @@ local options = { { "^%-%-jobs%=([0-9]+)$", function(o) - if not o or #o < 1 then return false end + if not o or #o < 1 then + return false + end jobs = tonumber(o) assert(jobs and jobs >= 1, "invalid number of jobs") return true @@ -481,7 +497,9 @@ local options = { { "^%-%-log%-proofs$", function(o) - if not o then return false end + if not o then + return false + end log_proofs = true return true end, @@ -489,7 +507,9 @@ local options = { { "^%-%-log%-annotations$", function(o) - if not o then return false end + if not o then + return false + end log_annotations = true return true end, @@ -497,7 +517,9 @@ local options = { { "^(%-%-periodic%-action%=(.*))$", function(all, v) - if not v then return false end + if not v then + return false + end string.gsub(v, "^([^%,]+),(.+)$", function(p, s) periodic_action_period = assert(util.parse_number(p), "invalid period " .. all) periodic_action_start = assert(util.parse_number(s), "invalid start " .. all) @@ -514,7 +536,9 @@ local options = { { "^(%-%-concurrency%=(.+))$", function(all, opts) - if not opts then return false end + if not opts then + return false + end local c = util.parse_options(opts, { update_merkle_tree = true, }) @@ -527,14 +551,21 @@ local options = { { "^%-%-uarch%-ram%-image%=(.*)$", function(o) - if not o or #o < 1 then return false end + if not o or #o < 1 then + return false + end uarch = uarch or {} uarch.ram = uarch.ram or {} uarch.ram.image_filename = o return true end, }, - { ".*", function(all) error("unrecognized option " .. all) end }, + { + ".*", + function(all) + error("unrecognized option " .. all) + end, + }, } local values = {} @@ -543,7 +574,9 @@ local values = {} for _, argument in ipairs({ ... }) do if argument:sub(1, 1) == "-" then for _, option in ipairs(options) do - if option[2](argument:match(option[1])) then break end + if option[2](argument:match(option[1])) then + break + end end else values[#values + 1] = argument @@ -553,9 +586,13 @@ end local command = assert(values[1], "missing command") assert(test_path, "missing test path") -if remote_address then protocol = require("cartesi." .. remote_protocol) end +if remote_address then + protocol = require("cartesi." .. remote_protocol) +end -local function advance_machine(machine, max_mcycle) return machine:run(max_mcycle) end +local function advance_machine(machine, max_mcycle) + return machine:run(max_mcycle) +end local function run_machine(machine, ctx, max_mcycle, advance_machine_fn) advance_machine_fn = advance_machine_fn or advance_machine @@ -563,13 +600,17 @@ local function run_machine(machine, ctx, max_mcycle, advance_machine_fn) while math.ult(mcycle, max_mcycle) do advance_machine_fn(machine, max_mcycle) mcycle = machine:read_mcycle() - if machine:read_iflags_H() then break end + if machine:read_iflags_H() then + break + end end ctx.read_htif_tohost_data = machine:read_htif_tohost_data() end local function advance_machine_with_uarch(machine) - if machine:run_uarch() == cartesi.UARCH_BREAK_REASON_UARCH_HALTED then machine:reset_uarch() end + if machine:run_uarch() == cartesi.UARCH_BREAK_REASON_UARCH_HALTED then + machine:reset_uarch() + end end local function run_machine_with_uarch(machine, ctx, max_mcycle) @@ -580,8 +621,14 @@ local function connect() local remote_stub = protocol.stub(remote_address) local version = assert(remote_stub.get_version(), "could not connect to remote cartesi machine at " .. remote_address) - local shutdown = function() remote_stub.shutdown() end - local mt = { __gc = function() pcall(shutdown) end } + local shutdown = function() + remote_stub.shutdown() + end + local mt = { + __gc = function() + pcall(shutdown) + end, + } setmetatable(cleanup, mt) return remote_stub, version end @@ -608,14 +655,18 @@ local function build_machine(ram_image) length = 0x40000, } }, } - if uarch then config.uarch = uarch end + if uarch then + config.uarch = uarch + end local runtime = { concurrency = { update_merkle_tree = concurrency_update_merkle_tree, }, } if remote_address then - if not remote then remote = connect() end + if not remote then + remote = connect() + end return assert(remote.machine(config, runtime)) end return assert(cartesi.machine(config, runtime)) @@ -647,8 +698,12 @@ local function print_machine(test_name, expected_cycles) end end -local function stderr(fmt, ...) io.stderr:write(string.format(fmt, ...)) end -local function fatal(fmt, ...) error(string.format(fmt, ...)) end +local function stderr(fmt, ...) + io.stderr:write(string.format(fmt, ...)) +end +local function fatal(fmt, ...) + error(string.format(fmt, ...)) +end local function check_and_print_result(machine, ctx) local halt_payload = machine:read_htif_tohost_data() >> 1 local expected_halt_payload = ctx.expected_halt_payload or 0 @@ -667,7 +722,9 @@ end local function hash(tests) local out = io.stdout - if output then out = assert(io.open(output, "w"), "error opening file: " .. output) end + if output then + out = assert(io.open(output, "w"), "error opening file: " .. output) + end for _, test in ipairs(tests) do local ram_image = test[1] local expected_cycles = test[2] @@ -697,7 +754,9 @@ local function hash(tests) end if status == cartesi.UARCH_BREAK_REASON_UARCH_HALTED then machine:reset_uarch() - if machine:read_iflags_H() then break end + if machine:read_iflags_H() then + break + end end end if machine:read_htif_tohost_data() >> 1 ~= expected_payload or machine:read_mcycle() ~= expected_cycles then @@ -725,7 +784,9 @@ end local function step(tests) local out = io.stdout - if output then out = assert(io.open(output, "w"), "error opening file: " .. output) end + if output then + out = assert(io.open(output, "w"), "error opening file: " .. output) + end local indentout = util.indentout local log_type = { annotations = log_annotations, proofs = log_proofs } out:write("[\n") @@ -764,7 +825,9 @@ local function step(tests) total_uarch_cycles = total_uarch_cycles + (final_uarch_cycle - init_uarch_cycle) if machine:read_uarch_halt_flag() then machine:reset_uarch() - if machine:read_iflags_H() then break end + if machine:read_iflags_H() then + break + end end if not periodic_action or total_uarch_cycles == next_action_uarch_cycle then local init_mcycle = machine:read_mcycle() @@ -772,13 +835,17 @@ local function step(tests) local log = machine:log_uarch_step(log_type) local final_mcycle = machine:read_mcycle() final_uarch_cycle = machine:read_uarch_cycle() - if total_logged_steps > 0 then out:write(",\n") end + if total_logged_steps > 0 then + out:write(",\n") + end util.dump_json_log(log, init_mcycle, init_uarch_cycle, final_mcycle, final_uarch_cycle, out, 3) total_uarch_cycles = total_uarch_cycles + 1 total_logged_steps = total_logged_steps + 1 if machine:read_uarch_halt_flag() then machine:reset_uarch() - if machine:read_iflags_H() then break end + if machine:read_iflags_H() then + break + end end end end @@ -813,7 +880,9 @@ local function list(tests) local indentout = util.indentout out:write('{\n "tests": [\n') for i, test in ipairs(tests) do - if i ~= 1 then out:write(",\n") end + if i ~= 1 then + out:write(",\n") + end indentout(out, 2, "{\n") indentout(out, 3, '"file": "' .. test[1] .. '",\n') indentout(out, 3, '"mcycle": ' .. test[2] .. "\n") @@ -829,14 +898,18 @@ end local function select_test(test_name, patt) local i, j = test_name:find(patt) - if i == 1 and j == #test_name then return true end + if i == 1 and j == #test_name then + return true + end i, j = test_name:find(patt, 1, true) return i == 1 and j == #test_name end local selected_tests = {} for _, test in ipairs(riscv_tests) do - if select_test(test[1], test_pattern) then selected_tests[#selected_tests + 1] = test end + if select_test(test[1], test_pattern) then + selected_tests[#selected_tests + 1] = test + end end local function run_host_and_uarch_machines(target, ctx, max_mcycle) @@ -877,7 +950,9 @@ local function run_host_and_uarch_machines(target, ctx, max_mcycle) tostring(uarch_iflags_H) ) end - if host_iflags_H then break end + if host_iflags_H then + break + end end local host_htif_tohost_data = host_machine:read_htif_tohost_data() local uarch_htif_tohost_data = uarch_machine:read_htif_tohost_data() diff --git a/tests/lua/cartesi/parallel.lua b/tests/lua/cartesi/parallel.lua index 9d1597282..29dd5feb4 100644 --- a/tests/lua/cartesi/parallel.lua +++ b/tests/lua/cartesi/parallel.lua @@ -46,7 +46,9 @@ local function parallel(list, jobs, fn) local pid, reason, rc = syswait.wait(any_children) while pid and pid ~= (opt and 0) do if reason == "exited" or reason == "killed" then -- ignore 'stopped' - if rc ~= 0 then num_errors = num_errors + 1 end + if rc ~= 0 then + num_errors = num_errors + 1 + end running = running - 1 end pid, reason, rc = syswait.wait(any_children, syswait[opt]) @@ -59,7 +61,9 @@ local function parallel(list, jobs, fn) while true do while running < jobs do i, row = iter(list, i) - if not row then goto done end + if not row then + goto done + end spawn_run_one(row) running = running + 1 end diff --git a/tests/lua/cartesi/tests/util.lua b/tests/lua/cartesi/tests/util.lua index 6b74f0d85..8c3d7bf9b 100644 --- a/tests/lua/cartesi/tests/util.lua +++ b/tests/lua/cartesi/tests/util.lua @@ -21,7 +21,9 @@ local PAGE_LOG2_SIZE = 12 local PAGE_SIZE = 1 << PAGE_LOG2_SIZE local WORD_LOG2_SIZE = 5 -local function adjust_path(path) return string.gsub(path or ".", "/*$", "") .. "/" end +local function adjust_path(path) + return string.gsub(path or ".", "/*$", "") .. "/" +end local test_util = { images_path = adjust_path(assert(os.getenv("CARTESI_IMAGES_PATH"))), @@ -58,7 +60,9 @@ test_util.uarch_programs.default = { } function test_util.create_test_uarch_program(instructions) - if not instructions then instructions = test_util.uarch_programs.default end + if not instructions then + instructions = test_util.uarch_programs.default + end local file_path = os.tmpname() local f = io.open(file_path, "wb") for _, insn in pairs(instructions) do @@ -76,7 +80,9 @@ function test_util.make_do_test(build_machine, type, config, runtime_config) end end -function test_util.disabled_test(description) print("Disabled test - " .. description) end +function test_util.disabled_test(description) + print("Disabled test - " .. description) +end local back_merkle_tree_meta = { __index = {} } @@ -106,7 +112,9 @@ function back_merkle_tree_meta.__index:pad_back(new_leaf_count) local j = 0 while j <= depth do local j_span = 0x1 << j - if j_span > new_leaf_count then break end + if j_span > new_leaf_count then + break + end -- is our smallest tree at depth j? if (self.m_leaf_count & j_span) ~= 0x0 then -- if so, we can add 2^j pristine leaves directly @@ -176,15 +184,21 @@ function test_util.file_exists(name) end function test_util.tohex(str) - return (str:gsub(".", function(c) return string.format("%02X", string.byte(c)) end)) + return (str:gsub(".", function(c) + return string.format("%02X", string.byte(c)) + end)) end function test_util.fromhex(str) - return (str:gsub("..", function(cc) return string.char(tonumber(cc, 16)) end)) + return (str:gsub("..", function(cc) + return string.char(tonumber(cc, 16)) + end)) end function test_util.split_string(inputstr, sep) - if sep == nil then sep = "%s" end + if sep == nil then + sep = "%s" + end local t = {} for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do table.insert(t, str) @@ -207,7 +221,9 @@ function test_util.check_proof(proof) return hash == proof.root_hash end -function test_util.align(v, el) return (v >> el << el) end +function test_util.align(v, el) + return (v >> el << el) +end function test_util.load_file(filename) local fd = assert(io.open(filename, "rb")) @@ -280,7 +296,9 @@ end -- temporary file local temp_file_meta = { __index = {} } -function temp_file_meta.__index:write(...) self.file:write(...) end +function temp_file_meta.__index:write(...) + self.file:write(...) +end function temp_file_meta.__index:read_all() self.file:seek("set", 0) @@ -292,7 +310,9 @@ function temp_file_meta.__index:close() os.remove(self.file_name) end -function temp_file_meta:__close() self:close() end +function temp_file_meta:__close() + self:close() +end function test_util.new_temp_file() local self = {} diff --git a/tests/lua/cmio-test.lua b/tests/lua/cmio-test.lua index b3db889b7..b951953ca 100755 --- a/tests/lua/cmio-test.lua +++ b/tests/lua/cmio-test.lua @@ -20,7 +20,9 @@ local cartesi = require("cartesi") local test_util = require("cartesi.tests.util") local test_data = require("cartesi.tests.data") -local function adjust_images_path(path) return string.gsub(path or ".", "/*$", "") .. "/" end +local function adjust_images_path(path) + return string.gsub(path or ".", "/*$", "") .. "/" +end local MACHINES_DIR = adjust_images_path(test_util.cmio_path) local remote_address @@ -54,26 +56,37 @@ local options = { { "^%-%-h$", function(all) - if not all then return false end + if not all then + return false + end help() end, }, { "^%-%-help$", function(all) - if not all then return false end + if not all then + return false + end help() end, }, { "^%-%-remote%-address%=(.*)$", function(o) - if not o or #o < 1 then return false end + if not o or #o < 1 then + return false + end remote_address = o return true end, }, - { ".*", function(all) error("unrecognized option " .. all) end }, + { + ".*", + function(all) + error("unrecognized option " .. all) + end, + }, } -- Process command line options @@ -81,7 +94,9 @@ local arguments = {} for _, argument in ipairs({ ... }) do if argument:sub(1, 1) == "-" then for _, option in ipairs(options) do - if option[2](argument:match(option[1])) then break end + if option[2](argument:match(option[1])) then + break + end end else arguments[#arguments + 1] = argument @@ -100,8 +115,14 @@ end local function connect() local remote = protocol.stub(remote_address) local version = assert(remote.get_version(), "could not connect to remote cartesi machine at " .. remote_address) - local shutdown = function() remote.shutdown() end - local mt = { __gc = function() pcall(shutdown) end } + local shutdown = function() + remote.shutdown() + end + local mt = { + __gc = function() + pcall(shutdown) + end, + } setmetatable(cleanup, mt) return remote, version end @@ -121,7 +142,9 @@ local function load_machine(name) skip_root_hash_store = true, } if machine_type ~= "local" then - if not remote then remote = connect() end + if not remote then + remote = connect() + end return assert(remote.machine(MACHINES_DIR .. name, runtime)) else return assert(cartesi.machine(MACHINES_DIR .. name, runtime)) @@ -137,7 +160,9 @@ local function get_yield(machine) return cmd, reason & m16, data & m32 end -local function next_input(machine, reason, data) machine:send_cmio_response(reason, data) end +local function next_input(machine, reason, data) + machine:send_cmio_response(reason, data) +end local function setup_advance(machine, data) assert(data) @@ -192,14 +217,18 @@ end local function check_outputs_root_hash(root_hash, output_hashes) local z = string.rep("\0", 32) - if #output_hashes == 0 then output_hashes = { z } end + if #output_hashes == 0 then + output_hashes = { z } + end for _ = 1, 63 do local parent_output_hashes = {} local child = 1 local parent = 1 while true do local c1 = output_hashes[child] - if not c1 then break end + if not c1 then + break + end local c2 = output_hashes[child + 1] if c2 then parent_output_hashes[parent] = cartesi.keccak(c1, c2) diff --git a/tests/lua/create-machines.lua b/tests/lua/create-machines.lua index 477d170e7..37c11edb3 100755 --- a/tests/lua/create-machines.lua +++ b/tests/lua/create-machines.lua @@ -20,10 +20,14 @@ local cartesi = require("cartesi") local util = require("cartesi.util") local test_util = require("cartesi.tests.util") -local function stderr_unsilenceable(fmt, ...) io.stderr:write(string.format(fmt, ...)) end +local function stderr_unsilenceable(fmt, ...) + io.stderr:write(string.format(fmt, ...)) +end local stderr = stderr_unsilenceable -local function adjust_images_path(path) return string.gsub(path or ".", "/*$", "") .. "/" end +local function adjust_images_path(path) + return string.gsub(path or ".", "/*$", "") .. "/" +end local function basedir(s) s = string.gsub(s, "/$", "") return string.match(s, "/.+[^/]+/") or "." @@ -62,7 +66,9 @@ local options = { { "^%-h$", function(all) - if not all then return false end + if not all then + return false + end help() return true end, @@ -70,7 +76,9 @@ local options = { { "^%-%-help$", function(all) - if not all then return false end + if not all then + return false + end help() return true end, @@ -78,7 +86,9 @@ local options = { { ".*", function(all) - if not all then return false end + if not all then + return false + end local not_option = all:sub(1, 1) ~= "-" if not_option or all == "--" then cmdline_opts_finished = true @@ -93,7 +103,9 @@ local options = { for _, a in ipairs(arg) do if not cmdline_opts_finished then for _, option in ipairs(options) do - if option[2](a:match(option[1])) then break end + if option[2](a:match(option[1])) then + break + end end end end @@ -111,7 +123,9 @@ end local function get_file_length(file_path) local file = io.open(file_path, "rb") - if file == nil then error("File not found: " .. file_path) end + if file == nil then + error("File not found: " .. file_path) + end local size = file:seek("end") file:close() return size @@ -151,7 +165,9 @@ end local function instantiate_filename(pattern, values) -- replace escaped % with something safe pattern = string.gsub(pattern, "%\\%%", "\0") - pattern = string.gsub(pattern, "%%(%a)", function(s) return values[s] or s end) + pattern = string.gsub(pattern, "%%(%a)", function(s) + return values[s] or s + end) -- restore escaped % return (string.gsub(pattern, "\0", "%")) end @@ -165,7 +181,9 @@ end local function create_machine(machine_name, command, config_func) stderr("Creating machine: " .. machine_name .. " ...\n") local config = create_default_config(IMAGES_DIR, command) - if config_func then config_func(config) end + if config_func then + config_func(config) + end local machine = cartesi.machine(config) machine:run(math.maxinteger) store_machine(machine, MACHINES_DIR .. machine_name) @@ -215,5 +233,9 @@ rollup-init bash /home/dapp/s.sh ) -- Should not work with shared buffers -create_machine("shared-rx-buffer-machine", "rollup accept", function(config) config.cmio.rx_buffer.shared = true end) -create_machine("shared-tx-buffer-machine", "rollup accept", function(config) config.cmio.tx_buffer.shared = true end) +create_machine("shared-rx-buffer-machine", "rollup accept", function(config) + config.cmio.rx_buffer.shared = true +end) +create_machine("shared-tx-buffer-machine", "rollup accept", function(config) + config.cmio.tx_buffer.shared = true +end) diff --git a/tests/lua/htif-cmio.lua b/tests/lua/htif-cmio.lua index aee7bd0e6..1116a7b10 100755 --- a/tests/lua/htif-cmio.lua +++ b/tests/lua/htif-cmio.lua @@ -38,7 +38,9 @@ local config_base = { }, } -local function stderr(...) io.stderr:write(string.format(...)) end +local function stderr(...) + io.stderr:write(string.format(...)) +end local final_mcycle = 1835101 local exit_payload = 0 diff --git a/tests/lua/htif-console.lua b/tests/lua/htif-console.lua index 4d0ce600e..9923e2e5b 100755 --- a/tests/lua/htif-console.lua +++ b/tests/lua/htif-console.lua @@ -32,7 +32,9 @@ local config_base = { }, } -local function stderr(...) io.stderr:write(string.format(...)) end +local function stderr(...) + io.stderr:write(string.format(...)) +end local final_mcycle = 2137 local exit_payload = 42 diff --git a/tests/lua/htif-yield.lua b/tests/lua/htif-yield.lua index 86d68e04f..a6169e252 100755 --- a/tests/lua/htif-yield.lua +++ b/tests/lua/htif-yield.lua @@ -59,14 +59,18 @@ local options = { { "^%-%-help$", function(all) - if not all then return false end + if not all then + return false + end help() end, }, { "^%-%-uarch$", function(all) - if not all then return false end + if not all then + return false + end run_with_uarch = true return true end, @@ -74,7 +78,9 @@ local options = { { "^%-%-uarch%-ram%-image%=(.*)$", function(o) - if not o or #o < 1 then return false end + if not o or #o < 1 then + return false + end uarch = uarch or {} uarch.ram = uarch.ram or {} uarch.ram.image_filename = o @@ -84,14 +90,18 @@ local options = { { "^%-%-test%-path%=(.*)$", function(o) - if not o or #o < 1 then return false end + if not o or #o < 1 then + return false + end test_path = o return true end, }, { ".*", - function(all) error("unrecognized option " .. all .. ". Use --help to obtain a list of supported options.") end, + function(all) + error("unrecognized option " .. all .. ". Use --help to obtain a list of supported options.") + end, }, } @@ -99,7 +109,9 @@ local options = { for _, argument in ipairs({ ... }) do if argument:sub(1, 1) == "-" then for _, option in ipairs(options) do - if option[2](argument:match(option[1])) then break end + if option[2](argument:match(option[1])) then + break + end end end end @@ -117,7 +129,9 @@ local config = { }, } -if uarch then config.uarch = uarch end +if uarch then + config.uarch = uarch +end local YIELD_MANUAL = cartesi.machine.HTIF_YIELD_CMD_MANUAL local YIELD_AUTOMATIC = cartesi.machine.HTIF_YIELD_CMD_AUTOMATIC @@ -171,11 +185,15 @@ local function run_machine_with_uarch(machine) end local function run_machine(machine) - if run_with_uarch then return run_machine_with_uarch(machine) end + if run_with_uarch then + return run_machine_with_uarch(machine) + end return machine:run() end -local function stderr(...) io.stderr:write(string.format(...)) end +local function stderr(...) + io.stderr:write(string.format(...)) +end local final_mcycle = 500 local exit_payload = 42 diff --git a/tests/lua/machine-bind.lua b/tests/lua/machine-bind.lua index be99b1456..2f56d3d56 100755 --- a/tests/lua/machine-bind.lua +++ b/tests/lua/machine-bind.lua @@ -75,21 +75,27 @@ local options = { { "^%-%-h$", function(all) - if not all then return false end + if not all then + return false + end help() end, }, { "^%-%-help$", function(all) - if not all then return false end + if not all then + return false + end help() end, }, { "^%-%-remote%-address%=(.*)$", function(o) - if not o or #o < 1 then return false end + if not o or #o < 1 then + return false + end remote_address = o return true end, @@ -97,16 +103,22 @@ local options = { { "^%-%-test%-path%=(.*)$", function(o) - if not o or #o < 1 then return false end + if not o or #o < 1 then + return false + end test_path = o - if string.sub(test_path, -1, -1) ~= "/" then error("test-path must end in '/'") end + if string.sub(test_path, -1, -1) ~= "/" then + error("test-path must end in '/'") + end return true end, }, { "^(%-%-concurrency%=(.+))$", function(all, opts) - if not opts then return false end + if not opts then + return false + end local c = util.parse_options(opts, { update_merkle_tree = true, }) @@ -116,7 +128,12 @@ local options = { return true end, }, - { ".*", function(all) error("unrecognized option " .. all) end }, + { + ".*", + function(all) + error("unrecognized option " .. all) + end, + }, } -- Process command line options @@ -124,7 +141,9 @@ local arguments = {} for _, argument in ipairs({ ... }) do if argument:sub(1, 1) == "-" then for _, option in ipairs(options) do - if option[2](argument:match(option[1])) then break end + if option[2](argument:match(option[1])) then + break + end end else arguments[#arguments + 1] = argument @@ -243,8 +262,14 @@ end local function connect() local remote = protocol.stub(remote_address) local version = assert(remote.get_version(), "could not connect to remote cartesi machine at " .. remote_address) - local shutdown = function() remote.shutdown() end - local mt = { __gc = function() pcall(shutdown) end } + local shutdown = function() + remote.shutdown() + end + local mt = { + __gc = function() + pcall(shutdown) + end, + } setmetatable(cleanup, mt) return remote, version end @@ -252,7 +277,9 @@ end local remote local function build_machine_config(config_options) - if not config_options then config_options = {} end + if not config_options then + config_options = {} + end -- Create new machine local initial_csr_values = get_cpu_csr_test_values() @@ -287,12 +314,16 @@ local function build_machine(type, config_options) local config, runtime = build_machine_config(config_options) local new_machine if type ~= "local" then - if not remote then remote = connect() end + if not remote then + remote = connect() + end new_machine = assert(remote.machine(config, runtime)) else new_machine = assert(cartesi.machine(config, runtime)) end - if config.uarch.ram and config.uarch.ram.image_filename then os.remove(config.uarch.ram.image_filename) end + if config.uarch.ram and config.uarch.ram.image_filename then + os.remove(config.uarch.ram.image_filename) + end return new_machine end @@ -356,7 +387,9 @@ print("\n\ntesting get_csr_address function binding") do_test("should return address value for csr register", function() local module = cartesi if machine_type ~= "local" then - if not remote then remote = connect() end + if not remote then + remote = connect() + end module = remote end -- Check CSR address @@ -370,7 +403,9 @@ print("\n\ntesting get_x_address function binding") do_test("should return address value for x registers", function() local module = cartesi if machine_type ~= "local" then - if not remote then remote = connect() end + if not remote then + remote = connect() + end module = remote end -- Check x address @@ -450,7 +485,9 @@ print("\n\ntesting get_default_config function binding") do_test("should return default machine config", function() local module = cartesi if machine_type ~= "local" then - if not remote then remote = connect() end + if not remote then + remote = connect() + end module = remote end test_config(module.machine.get_default_config()) @@ -578,7 +615,9 @@ end) do_test("should error if target mcycle is smaller than current mcycle", function(machine) machine:write_mcycle(MAX_MCYCLE) assert(machine:read_mcycle() == MAX_MCYCLE) - local success, err = pcall(function() machine:run(MAX_MCYCLE - 1) end) + local success, err = pcall(function() + machine:run(MAX_MCYCLE - 1) + end) assert(success == false) assert(err:match("mcycle is past")) assert(machine:read_mcycle() == MAX_MCYCLE) @@ -587,7 +626,9 @@ end) do_test("should error if target uarch_cycle is smaller than current uarch_cycle", function(machine) machine:write_uarch_cycle(MAX_UARCH_CYCLE) assert(machine:read_uarch_cycle() == MAX_UARCH_CYCLE) - local success, err = pcall(function() machine:run_uarch(MAX_UARCH_CYCLE - 1) end) + local success, err = pcall(function() + machine:run_uarch(MAX_UARCH_CYCLE - 1) + end) assert(success == false) assert(err:match("uarch_cycle is past")) assert(machine:read_uarch_cycle() == MAX_UARCH_CYCLE) @@ -697,7 +738,9 @@ print("\n\ntesting step and verification") do_test("machine step should pass verifications", function(machine) local module = cartesi if machine_type ~= "local" then - if not remote then remote = connect() end + if not remote then + remote = connect() + end module = remote end local initial_hash = machine:get_root_hash() @@ -712,7 +755,9 @@ do_test("Step log must contain conssitent data hashes", function(machine) local wrong_hash = string.rep("\0", 32) local module = cartesi if machine_type ~= "local" then - if not remote then remote = connect() end + if not remote then + remote = connect() + end module = remote end local log = machine:log_uarch_step({ proofs = false, annotations = false }) @@ -744,7 +789,9 @@ end) do_test("step when uarch cycle is max", function(machine) local module = cartesi if machine_type ~= "local" then - if not remote then remote = connect() end + if not remote then + remote = connect() + end module = remote end machine:write_uarch_cycle(MAX_UARCH_CYCLE) @@ -923,7 +970,9 @@ end test_util.make_do_test(build_machine, machine_type, { uarch = test_reset_uarch_config })( "Testing reset_uarch without logging", - function(machine) test_reset_uarch(machine, false, false, false) end + function(machine) + test_reset_uarch(machine, false, false, false) + end ) for _, with_proofs in ipairs({ true, false }) do @@ -933,7 +982,9 @@ for _, with_proofs in ipairs({ true, false }) do .. tostring(with_proofs) .. ", annotations=" .. tostring(with_annotations), - function(machine) test_reset_uarch(machine, true, with_proofs, with_annotations) end + function(machine) + test_reset_uarch(machine, true, with_proofs, with_annotations) + end ) end end @@ -942,7 +993,9 @@ test_util.make_do_test(build_machine, machine_type, { uarch = test_reset_uarch_c "Testing verify_uarch_reset_state_transition", function(machine) local module = cartesi - if machine_type ~= "local" then module = remote end + if machine_type ~= "local" then + module = remote + end local initial_hash = machine:get_root_hash() local log = machine:log_uarch_reset({ proofs = true, annotations = true }) local final_hash = machine:get_root_hash() @@ -962,7 +1015,9 @@ test_util.make_do_test(build_machine, machine_type, { uarch = test_reset_uarch_c "Testing verify_uarch_reset_log", function(machine) local module = cartesi - if machine_type ~= "local" then module = remote end + if machine_type ~= "local" then + module = remote + end local log = machine:log_uarch_reset({ proofs = true, annotations = true }) module.machine.verify_uarch_reset_log(log, {}) end @@ -979,7 +1034,11 @@ test_util.make_do_test(build_machine, machine_type, { uarch = test_reset_uarch_c local tmpname = os.tmpname() local deleter = {} - setmetatable(deleter, { __gc = function() os.remove(tmpname) end }) + setmetatable(deleter, { + __gc = function() + os.remove(tmpname) + end, + }) local tmp = io.open(tmpname, "w+") util.dump_log(log, tmp) tmp:seek("set", 0) @@ -1000,7 +1059,9 @@ test_util.make_do_test(build_machine, machine_type, { uarch = test_reset_uarch_c "Log uarch reset with large_data option set must have consistent read and written data", function(machine) local module = cartesi - if machine_type ~= "local" then module = remote end + if machine_type ~= "local" then + module = remote + end -- reset uarch and get log local log = machine:log_uarch_reset({ proofs = true, annotations = true, large_data = true }) assert(#log.accesses == 1, "log should have 1 access") @@ -1028,7 +1089,9 @@ test_util.make_do_test(build_machine, machine_type, { uarch = test_reset_uarch_c do_test("Test unhappy paths of verify_uarch_reset_state_transition", function(machine) local module = cartesi if machine_type ~= "local" then - if not remote then remote = connect() end + if not remote then + remote = connect() + end module = remote end local bad_hash = string.rep("\0", 32) @@ -1044,39 +1107,46 @@ do_test("Test unhappy paths of verify_uarch_reset_state_transition", function(ma 'Error text "' .. err .. '" does not match expected "' .. expected_error .. '"' ) end - assert_error("too few accesses in log", function(log) log.accesses = {} end) - assert_error( - "expected address of access 1 to be the start address of the uarch state", - function(log) log.accesses[1].address = 0 end - ) + assert_error("too few accesses in log", function(log) + log.accesses = {} + end) + assert_error("expected address of access 1 to be the start address of the uarch state", function(log) + log.accesses[1].address = 0 + end) - assert_error( - "expected access 1 to write 2%^22 bytes to uarchState", - function(log) log.accesses[1].log2_size = 64 end - ) + assert_error("expected access 1 to write 2%^22 bytes to uarchState", function(log) + log.accesses[1].log2_size = 64 + end) - assert_error("hash length must be 32 bytes", function(log) log.accesses[#log.accesses].read_hash = nil end) - assert_error("Mismatch in root hash of access 1", function(log) log.accesses[1].read_hash = bad_hash end) - assert_error( - "access log was not fully consumed", - function(log) log.accesses[#log.accesses + 1] = log.accesses[1] end - ) - assert_error("hash length must be 32 bytes", function(log) log.accesses[#log.accesses].written_hash = nil end) - assert_error( - "invalid written %(expected% string with 2%^22 bytes%)", - function(log) log.accesses[#log.accesses].written = "\0" end - ) - assert_error( - "written hash and written data mismatch at access 1", - function(log) log.accesses[#log.accesses].written = string.rep("\0", 2 ^ 22) end - ) - assert_error("Mismatch in root hash of access 1", function(log) log.accesses[1].sibling_hashes[1] = bad_hash end) + assert_error("hash length must be 32 bytes", function(log) + log.accesses[#log.accesses].read_hash = nil + end) + assert_error("Mismatch in root hash of access 1", function(log) + log.accesses[1].read_hash = bad_hash + end) + assert_error("access log was not fully consumed", function(log) + log.accesses[#log.accesses + 1] = log.accesses[1] + end) + assert_error("hash length must be 32 bytes", function(log) + log.accesses[#log.accesses].written_hash = nil + end) + assert_error("invalid written %(expected% string with 2%^22 bytes%)", function(log) + log.accesses[#log.accesses].written = "\0" + end) + assert_error("written hash and written data mismatch at access 1", function(log) + log.accesses[#log.accesses].written = string.rep("\0", 2 ^ 22) + end) + assert_error("Mismatch in root hash of access 1", function(log) + log.accesses[1].sibling_hashes[1] = bad_hash + end) end) do_test("Test unhappy paths of verify_uarch_step_state_transition", function(machine) local module = cartesi if machine_type ~= "local" then - if not remote then remote = connect() end + if not remote then + remote = connect() + end module = remote end local bad_hash = string.rep("\0", 32) @@ -1092,34 +1162,51 @@ do_test("Test unhappy paths of verify_uarch_step_state_transition", function(mac 'Error text "' .. err .. '" does not match expected "' .. expected_error .. '"' ) end - assert_error("too few accesses in log", function(log) log.accesses = {} end) - assert_error("expected access 1 to read uarch.uarch_cycle", function(log) log.accesses[1].address = 0 end) - assert_error( - "expected access 1 to read 2%^5 bytes from uarch.uarch_cycle", - function(log) log.accesses[1].log2_size = 2 end - ) - assert_error("target size cannot be greater than root size", function(log) log.accesses[1].log2_size = 65 end) - assert_error("missing read uarch.uarch_cycle data at access 1", function(log) log.accesses[1].read = nil end) - assert_error("invalid read %(expected string with 2%^5 bytes%)", function(log) log.accesses[1].read = "\0" end) + assert_error("too few accesses in log", function(log) + log.accesses = {} + end) + assert_error("expected access 1 to read uarch.uarch_cycle", function(log) + log.accesses[1].address = 0 + end) + assert_error("expected access 1 to read 2%^5 bytes from uarch.uarch_cycle", function(log) + log.accesses[1].log2_size = 2 + end) + assert_error("target size cannot be greater than root size", function(log) + log.accesses[1].log2_size = 65 + end) + assert_error("missing read uarch.uarch_cycle data at access 1", function(log) + log.accesses[1].read = nil + end) + assert_error("invalid read %(expected string with 2%^5 bytes%)", function(log) + log.accesses[1].read = "\0" + end) assert_error( "logged read data of uarch.uarch_cycle data does not hash to the logged read hash at access 1", - function(log) log.accesses[1].read_hash = bad_hash end - ) - assert_error("hash length must be 32 bytes", function(log) log.accesses[#log.accesses].read_hash = nil end) - assert_error( - "access log was not fully consumed", - function(log) log.accesses[#log.accesses + 1] = log.accesses[1] end - ) - assert_error("hash length must be 32 bytes", function(log) log.accesses[#log.accesses].written_hash = nil end) - assert_error( - "invalid written %(expected string with 2%^5 bytes%)", - function(log) log.accesses[#log.accesses].written = "\0" end + function(log) + log.accesses[1].read_hash = bad_hash + end ) + assert_error("hash length must be 32 bytes", function(log) + log.accesses[#log.accesses].read_hash = nil + end) + assert_error("access log was not fully consumed", function(log) + log.accesses[#log.accesses + 1] = log.accesses[1] + end) + assert_error("hash length must be 32 bytes", function(log) + log.accesses[#log.accesses].written_hash = nil + end) + assert_error("invalid written %(expected string with 2%^5 bytes%)", function(log) + log.accesses[#log.accesses].written = "\0" + end) assert_error( "logged written data of uarch.cycle does not hash to the logged written hash at access 7", - function(log) log.accesses[#log.accesses].written = string.rep("\0", 32) end + function(log) + log.accesses[#log.accesses].written = string.rep("\0", 32) + end ) - assert_error("Mismatch in root hash of access 1", function(log) log.accesses[1].sibling_hashes[1] = bad_hash end) + assert_error("Mismatch in root hash of access 1", function(log) + log.accesses[1].sibling_hashes[1] = bad_hash + end) end) print("\n\n testing unsupported uarch instructions ") @@ -1179,22 +1266,24 @@ do_test("send_cmio_response fails if iflags.Y is not set", function(machine) local data = string.rep("a", 1 << cartesi.PMA_CMIO_RX_BUFFER_LOG2_SIZE) machine:reset_iflags_Y() assert(machine:read_iflags_Y() == false) - test_util.assert_error("iflags.Y is not set", function() machine:send_cmio_response(reason, data) end) - test_util.assert_error("iflags.Y is not set", function() machine:log_send_cmio_response(reason, data, {}) end) + test_util.assert_error("iflags.Y is not set", function() + machine:send_cmio_response(reason, data) + end) + test_util.assert_error("iflags.Y is not set", function() + machine:log_send_cmio_response(reason, data, {}) + end) end) do_test("send_cmio_response fails if data is too big", function(machine) local reason = 1 local data_too_big = string.rep("a", 1 + (1 << cartesi.PMA_CMIO_RX_BUFFER_LOG2_SIZE)) machine:set_iflags_Y() - test_util.assert_error( - "address range not entirely in memory PMA", - function() machine:send_cmio_response(reason, data_too_big) end - ) - test_util.assert_error( - "address range not entirely in memory PMA", - function() machine:log_send_cmio_response(reason, data_too_big, {}) end - ) + test_util.assert_error("address range not entirely in memory PMA", function() + machine:send_cmio_response(reason, data_too_big) + end) + test_util.assert_error("address range not entirely in memory PMA", function() + machine:log_send_cmio_response(reason, data_too_big, {}) + end) end) -- asserts that an access has the expected key values @@ -1248,7 +1337,9 @@ local function test_send_cmio_input_with_different_arguments() local log_type = { proofs = proofs, annotations = annotations, large_data = large_data } local module = cartesi if machine_type ~= "local" then - if not remote then remote = connect() end + if not remote then + remote = connect() + end module = remote end assert_before_cmio_response_sent(machine) @@ -1346,7 +1437,9 @@ do_test("send_cmio_response with different data sizes", function(machine) local rx_buffer_size = 1 << cartesi.PMA_CMIO_RX_BUFFER_LOG2_SIZE local initial_rx_buffer = string.rep("x", rx_buffer_size) local reason = 1 - local function padded_data(data, len, padding) return data .. string.rep(padding, len - #data) end + local function padded_data(data, len, padding) + return data .. string.rep(padding, len - #data) + end for _, case in ipairs(test_cases) do -- test logging and lo not logging for _, logging in ipairs({ false, true }) do @@ -1390,7 +1483,9 @@ end) do_test("send_cmio_response of zero bytes", function(machine) local module = cartesi if machine_type ~= "local" then - if not remote then remote = connect() end + if not remote then + remote = connect() + end module = remote end local rx_buffer_size = 1 << cartesi.PMA_CMIO_RX_BUFFER_LOG2_SIZE diff --git a/tests/lua/machine-test.lua b/tests/lua/machine-test.lua index d84a71194..c59a51f77 100755 --- a/tests/lua/machine-test.lua +++ b/tests/lua/machine-test.lua @@ -63,21 +63,27 @@ local options = { { "^%-%-h$", function(all) - if not all then return false end + if not all then + return false + end help() end, }, { "^%-%-help$", function(all) - if not all then return false end + if not all then + return false + end help() end, }, { "^%-%-remote%-address%=(.*)$", function(o) - if not o or #o < 1 then return false end + if not o or #o < 1 then + return false + end remote_address = o return true end, @@ -85,13 +91,22 @@ local options = { { "^%-%-test%-path%=(.*)$", function(o) - if not o or #o < 1 then return false end + if not o or #o < 1 then + return false + end test_path = o - if string.sub(test_path, -1, -1) ~= "/" then error("test-path must end in '/'") end + if string.sub(test_path, -1, -1) ~= "/" then + error("test-path must end in '/'") + end return true end, }, - { ".*", function(all) error("unrecognized option " .. all) end }, + { + ".*", + function(all) + error("unrecognized option " .. all) + end, + }, } -- Process command line options @@ -99,7 +114,9 @@ local arguments = {} for _, argument in ipairs({ ... }) do if argument:sub(1, 1) == "-" then for _, option in ipairs(options) do - if option[2](argument:match(option[1])) then break end + if option[2](argument:match(option[1])) then + break + end end else arguments[#arguments + 1] = argument @@ -118,8 +135,14 @@ end local function connect() local remote = protocol.stub(remote_address) local version = assert(remote.get_version(), "could not connect to remote cartesi machine at " .. remote_address) - local shutdown = function() remote.shutdown() end - local mt = { __gc = function() pcall(shutdown) end } + local shutdown = function() + remote.shutdown() + end + local mt = { + __gc = function() + pcall(shutdown) + end, + } setmetatable(cleanup, mt) return remote, version end @@ -136,7 +159,9 @@ local function build_machine(type, config, runtime_config) } local new_machine if type ~= "local" then - if not remote then remote = connect() end + if not remote then + remote = connect() + end new_machine = assert(remote.machine(config, runtime_config)) else new_machine = assert(cartesi.machine(config, runtime_config)) @@ -199,7 +224,9 @@ do_test("proof check should pass", function(machine) -- Find ram memory range local ram for _, v in ipairs(machine:get_memory_ranges()) do - if v.description == "RAM" then ram = v end + if v.description == "RAM" then + ram = v + end end -- Ccalculate hash of ram local ram_log2_size = math.ceil(math.log(ram.length, 2)) @@ -268,7 +295,9 @@ if machine_type == "local" then soft_yield = true, })("check soft yield", function(machine) -- The following is a RISC-V bytecode that cause a soft yield immediately, - local function sraiw(rd, rs1, shamt) return 0x4000501b | (rd << 7) | (rs1 << 15) | (shamt << 20) end + local function sraiw(rd, rs1, shamt) + return 0x4000501b | (rd << 7) | (rs1 << 15) | (shamt << 20) + end local soft_yield_insn = sraiw(0, 31, 7) machine:write_memory(machine:read_pc(), string.pack("= 1, "invalid number of jobs") return true @@ -203,7 +219,9 @@ local options = { { "^%-%-proofs$", function(o) - if not o or #o < 1 then return false end + if not o or #o < 1 then + return false + end proofs = true return true end, @@ -211,13 +229,20 @@ local options = { { "^%-%-proofs%-frequency%=(.+)$", function(n) - if not n then return false end + if not n then + return false + end proofs_frequency = assert(util.parse_number(n), "invalid proofs frequency " .. n) assert(proofs_frequency > 0, "proofs frequency must be > 0") return true end, }, - { ".*", function(all) error("unrecognized option " .. all) end }, + { + ".*", + function(all) + error("unrecognized option " .. all) + end, + }, } local values = {} @@ -226,7 +251,9 @@ local values = {} for _, argument in ipairs({ ... }) do if argument:sub(1, 1) == "-" then for _, option in ipairs(options) do - if option[2](argument:match(option[1])) then break end + if option[2](argument:match(option[1])) then + break + end end else values[#values + 1] = argument @@ -236,12 +263,18 @@ end local command = assert(values[1], "missing command") assert(test_path, "missing test path") -local function stderr(fmt, ...) io.stderr:write(string.format(fmt, ...)) end -local function fatal(fmt, ...) error(string.format(fmt, ...)) end +local function stderr(fmt, ...) + io.stderr:write(string.format(fmt, ...)) +end +local function fatal(fmt, ...) + error(string.format(fmt, ...)) +end local function build_machine(test_name) local uarch_ram = {} - if test_name then uarch_ram.image_filename = test_path .. "/" .. test_name end + if test_name then + uarch_ram.image_filename = test_path .. "/" .. test_name + end local config = { ram = { length = 0x20000, @@ -329,9 +362,13 @@ local function run(tests) uarch_run_success = false, } local machine = build_machine(ctx.ram_image) - local uarch_run_success, err = pcall(function() machine:run_uarch(2 * ctx.expected_cycles) end) + local uarch_run_success, err = pcall(function() + machine:run_uarch(2 * ctx.expected_cycles) + end) ctx.uarch_run_success = uarch_run_success - if not uarch_run_success then ctx.actual_error = err end + if not uarch_run_success then + ctx.actual_error = err + end check_test_result(machine, ctx) end) @@ -355,19 +392,25 @@ end local function select_test(test_name, patt) local i, j = test_name:find(patt) - if i == 1 and j == #test_name then return true end + if i == 1 and j == #test_name then + return true + end i, j = test_name:find(patt, 1, true) return i == 1 and j == #test_name end -local function make_json_log_file_name(test_name, suffix) return test_name .. (suffix or "") .. ".json" end +local function make_json_log_file_name(test_name, suffix) + return test_name .. (suffix or "") .. ".json" +end local function create_json_log_file(test_name, suffix) local file_path = output_dir .. "/" .. make_json_log_file_name(test_name, suffix) return assert(io.open(file_path, "w"), "error opening file " .. file_path) end -local function open_steps_json_log(test_name) return create_json_log_file(test_name, "-steps") end +local function open_steps_json_log(test_name) + return create_json_log_file(test_name, "-steps") +end local function write_sibling_hashes_to_log(sibling_hashes, out, indent) util.indentout(out, indent, '"sibling_hashes": [\n') @@ -388,14 +431,18 @@ local function write_access_to_log(access, out, indent, last) util.indentout(out, indent + 1, '"address": %u,\n', access.address) util.indentout(out, indent + 1, '"log2_size": %u,\n', access.log2_size) local read_value = "" -- Solidity JSON parser breaks, if this field is null - if access.read then read_value = util.hexstring(access.read) end + if access.read then + read_value = util.hexstring(access.read) + end util.indentout(out, indent + 1, '"read_value": "%s",\n', read_value) util.indentout(out, indent + 1, '"read_hash": "%s",\n', util.hexhash(access.read_hash)) local written_value = "" local written_hash = "" if access.type == "write" then written_hash = util.hexhash(access.written_hash) - if access.written then written_value = util.hexstring(access.written) end + if access.written then + written_value = util.hexstring(access.written) + end end util.indentout(out, indent + 1, '"written_value": "%s",\n', written_value) util.indentout(out, indent + 1, '"written_hash": "%s"', written_hash) @@ -406,7 +453,9 @@ local function write_access_to_log(access, out, indent, last) out:write("\n") end util.indentout(out, indent, "}") - if not last then out:write(",") end + if not last then + out:write(",") + end out:write("\n") end @@ -419,11 +468,15 @@ local function write_log_to_file(log, out, indent, last) end util.indentout(out, indent + 1, "]\n") util.indentout(out, indent, "}") - if not last then out:write(",") end + if not last then + out:write(",") + end out:write("\n") end -local function catalog_entry_file_name(name) return output_dir .. "/" .. make_json_log_file_name(name, "-catalog-entry") end +local function catalog_entry_file_name(name) + return output_dir .. "/" .. make_json_log_file_name(name, "-catalog-entry") +end local function write_catalog_json_log_entry(out, logFilename, ctx) util.indentout( @@ -449,7 +502,9 @@ local function create_catalog_json_log_entry(ctx) end local function should_log_proofs() - if not proofs then return false end + if not proofs then + return false + end return (total_steps_counter % proofs_frequency) == 0 end @@ -467,7 +522,9 @@ local function run_machine_writing_json_logs(machine, ctx) step_count = step_count + 1 local halted = machine:read_uarch_halt_flag() write_log_to_file(log, out, indent + 1, halted) - if halted then break end + if halted then + break + end end ctx.step_count = step_count ctx.uarch_run_success = true @@ -528,7 +585,9 @@ local function json_step_logs(tests) local loggable_tests = {} for _, test in ipairs(tests) do local expected_error_pattern = test[3] - if not expected_error_pattern then loggable_tests[#loggable_tests + 1] = test end + if not expected_error_pattern then + loggable_tests[#loggable_tests + 1] = test + end end -- note: function may run in a separate process @@ -602,7 +661,9 @@ end local selected_tests = {} for _, test in ipairs(riscv_tests) do - if select_test(test[1], test_pattern) then selected_tests[#selected_tests + 1] = test end + if select_test(test[1], test_pattern) then + selected_tests[#selected_tests + 1] = test + end end if #selected_tests < 1 then