initial commit

This commit is contained in:
2026-05-01 17:30:33 +02:00
commit b2f75735a1

225
init.lua Normal file
View File

@@ -0,0 +1,225 @@
local gpu = component.list('gpu')();
if not gpu then error("can't run without a gpu!"); end
local screen = component.list('screen')();
if not screen then error("can't run without a screen!"); end
local w,h = component.invoke(gpu, 'getResolution');
component.invoke(gpu, "bind", screen);
local emulog = function() end;
if debug and debug.print then emulog = debug.print end
local tests = {
{name = "component.methods", run = function()
if not component.methods then return "FAIL" end
local ok, val = pcall(component.methods, gpu);
if not ok then return "FAIL" end
if not val.set or not val.setForeground or not val.setBackground then
return "FAIL"
end
return "PASS"
end},
{name = "component.slot", run = function()
local slot = component.slot(gpu)
if not slot then return "FAIL" end
return "PASS"
end},
{name = "component.proxy", run = function()
local gpuprox = component.proxy(gpu);
if gpuprox.address ~= gpu then return "FAIL" end
if gpuprox.slot ~= component.slot(gpu) then return "FAIL" end
if gpuprox.type ~= "gpu" then return "FAIL" end
local methods = component.methods(gpu);
for k,v in pairs(methods) do
if not gpuprox[k] then return "FAIL" end
end
return "PASS"
end},
{name = "eeprom: readable (code & data)", run = function()
local eeprom = component.list('eeprom')()
if not eeprom then return "SKIP" end
local code = component.invoke(eeprom, 'get');
if not code then return "FAIL" end
local data = component.invoke(eeprom, 'getData');
if not data then return "FAIL" end
return "PASS"
end},
{name = "eeprom: read & writable (code & data)", run = function()
local eeprom = component.list('eeprom')()
if not eeprom then return "SKIP" end
local methods = component.methods(eeprom)
if not methods.isReadOnly then return "SKIP" end
if component.invoke(eeprom, 'isReadOnly') then
return "SKIP"
end
local code = component.invoke(eeprom, 'get');
if not code then return "FAIL" end
local data = component.invoke(eeprom, 'getData');
if not data then return "FAIL" end
local testData = "HELLO MY NAME IS BLENDI GOOSE AND I AM WRITING THIS CODE RIGHT NOW; wow what a good test message thank you, me."
component.invoke(eeprom, 'set', testData);
if testData ~= component.invoke(eeprom, 'get') then
return "FAIL"
end
component.invoke(eeprom, 'set', code); -- don't wanna fuck up the thing lol
component.invoke(eeprom, 'setData', testData);
if testData ~= component.invoke(eeprom, 'getData') then
return "FAIL"
end
component.invoke(eeprom, 'setData', data);
return "PASS"
end},
{name = "eeprom: read label", run = function()
local eeprom = component.list('eeprom')()
if not eeprom then return "SKIP" end
local label, err = component.invoke(eeprom, 'getLabel');
if err then return "FAIL" end
return "PASS"
end},
{name = "eeprom: r/w label", run = function()
local eeprom = component.list('eeprom')()
if not eeprom then return "SKIP" end
local methods = component.methods(eeprom)
if not methods.isReadOnly then return "SKIP" end
if component.invoke(eeprom, 'isReadOnly') then
return "SKIP"
end
local label, err = component.invoke(eeprom, 'getLabel');
if err then return "FAIL" end
local testlabel = "I AM A TEST"
component.invoke(eeprom, 'setLabel', testlabel);
if testlabel ~= component.invoke(eeprom, 'getLabel') then
return "FAIL"
end
component.invoke(eeprom, 'setLabel', label)
return "PASS"
end},
{name = "eeprom: other methods", run = function()
local eeprom = component.list('eeprom')();
if not component.invoke(eeprom, 'getSize') then return "FAIL" end
if not component.invoke(eeprom, 'getDataSize') then return "FAIL" end
if not component.invoke(eeprom, 'getChecksum') then return "FAIL" end
return "PASS"
end}
}
local page = 1
local selected = 1
local perpage = h - 1;
local pagec = math.ceil(#tests / perpage)
function render()
component.invoke(gpu, "setForeground", 0xffffff);
component.invoke(gpu, "setBackground", 0x000000);
component.invoke(gpu, "set", 1, 1, "Shitfucker, page " .. tostring(page) .. '/' .. tostring(pagec));
local pagelen = math.min(perpage, #tests - (page-1)*perpage)
for i = 1,pagelen do
local testid = i + (page-1)*perpage
local test = tests[testid];
local y = i + 1;
component.invoke(gpu, "set", 1, y, string.rep(" ", w))
component.invoke(gpu, "set", 7, y, test.name);
local state = test.state or "TEST"
if i == selected then
component.invoke(gpu, "setForeground", 0x000000);
component.invoke(gpu, "setBackground", 0xffffff);
end
component.invoke(gpu, "set", 2, y, state);
if i == selected then
component.invoke(gpu, "setForeground", 0xffffff);
component.invoke(gpu, "setBackground", 0x000000);
end
end
for i = pagelen+1, perpage do
component.invoke(gpu, "set", 1, i+1, string.rep(" ", w))
end
end
while true do
render()
local event = {computer.pullSignal(0.1)}
if event[1] == "key_down" then
local key = event[4]
if key == 0xcb then -- left
page = page - 1;
elseif key == 0xcd then -- right
page = page + 1;
end
if page < 1 then page = 1 end
if page > pagec then page = pagec end
if key == 0xc8 then -- up
selected = selected - 1
elseif key == 0xd0 then -- down
selected = selected + 1
end
local pagelen = math.min(perpage, #tests - (page-1)*perpage)
if selected < 1 then selected = 1 end
if selected > pagelen then selected = pagelen end
local char = event[3]
if char == "\r" or key == 0x1c then -- enter
local testid = selected + (page-1)*perpage
local test = tests[testid]
local ok, res = pcall(test.run)
if not ok then
emulog(res)
test.state = "CRASH"
else
if res then test.state = res else test.state = "FAIL" end
end
end
end
end