From e18bece3df8911102c92f60fc06fa5da62438c35 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 6 Mar 2016 10:20:45 +0100 Subject: [PATCH 1/3] Make tests more reliable on "early errors" When e.g. test-leaks.lua fails, it will cause a Lua error before starting the test runner. This means that the test will just hang, because nothing causes awesome to quit. Handle this by starting a timer when the test runner is loaded and quitting awesome in there if no test run was started yet. This only works if all tests load the runner before doing anything that could fail, so the require("_runner") is moved to the beginning in every test. Signed-off-by: Uli Schlachter --- tests/_runner.lua | 16 ++++++++++++++++ tests/test-awful-widget-watch.lua | 3 ++- tests/test-benchmark.lua | 3 ++- tests/test-focus.lua | 3 ++- tests/test-leak-client.lua | 3 ++- tests/test-leaks.lua | 3 ++- tests/test-spawn-snid.lua | 3 ++- tests/test-spawn.lua | 3 ++- 8 files changed, 30 insertions(+), 7 deletions(-) diff --git a/tests/_runner.lua b/tests/_runner.lua index 86dedecb..56860de2 100644 --- a/tests/_runner.lua +++ b/tests/_runner.lua @@ -16,6 +16,20 @@ runner.add_to_default_rules = function(r) table.insert(awful.rules.rules, r) end +-- Was the runner started already? +local running = false + +-- This is used if a test causes errors before starting the runner +timer.start_new(1, function() + if not running then + io.stderr:write("Error: run_steps() was never called\n") + if not runner.quit_awesome_on_error then + io.stderr:write("Keeping awesome open...\n") + return -- keep awesome open on error. + end + awesome.quit() + end +end) runner.run_steps = function(steps) -- Setup timer/timeout to limit waiting for signal and quitting awesome. @@ -24,6 +38,8 @@ runner.run_steps = function(steps) local wait=20 local step=1 local step_count=0 + assert(not running, "run_steps() was called twice") + running = true t:connect_signal("timeout", function() timer.delayed_call(function() io.flush() -- for "tail -f". step_count = step_count + 1 diff --git a/tests/test-awful-widget-watch.lua b/tests/test-awful-widget-watch.lua index f0c03d32..0a88583a 100644 --- a/tests/test-awful-widget-watch.lua +++ b/tests/test-awful-widget-watch.lua @@ -1,5 +1,6 @@ --- Test for awful.widget.watch +local runner = require("_runner") local watch = require("awful.widget.watch") local callbacks_done = 0 @@ -25,6 +26,6 @@ local steps = { end end } -require("_runner").run_steps(steps) +runner.run_steps(steps) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/test-benchmark.lua b/tests/test-benchmark.lua index ca35f171..c725de97 100644 --- a/tests/test-benchmark.lua +++ b/tests/test-benchmark.lua @@ -1,6 +1,7 @@ -- Some benchmarks that aren't really tests, but are included here anyway so -- that we notice if they break. +local runner = require("_runner") local awful = require("awful") local GLib = require("lgi").GLib local create_wibox = require("_wibox_helper").create_wibox @@ -75,6 +76,6 @@ benchmark(relayout_textclock, "relayout textclock") benchmark(redraw_textclock, "redraw textclock") benchmark(e2e_tag_switch, "tag switch") -require("_runner").run_steps({ function() return true end }) +runner.run_steps({ function() return true end }) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/test-focus.lua b/tests/test-focus.lua index 084be2fb..41b3cd56 100644 --- a/tests/test-focus.lua +++ b/tests/test-focus.lua @@ -1,6 +1,7 @@ --- Tests for focus signals / property. -- Test for https://github.com/awesomeWM/awesome/issues/134. +local runner = require("_runner") local awful = require("awful") local beautiful = require("beautiful") @@ -44,6 +45,6 @@ local steps = { end } -require("_runner").run_steps(steps) +runner.run_steps(steps) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/test-leak-client.lua b/tests/test-leak-client.lua index c70bf369..c6d209bf 100644 --- a/tests/test-leak-client.lua +++ b/tests/test-leak-client.lua @@ -1,4 +1,5 @@ -- Some memory leak checks involving clients as integration tests. +local runner = require("_runner") local awful = require("awful") local wibox = require("wibox") @@ -78,6 +79,6 @@ local steps = { end, } -require("_runner").run_steps(steps) +runner.run_steps(steps) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/test-leaks.lua b/tests/test-leaks.lua index e271bc55..d12d652e 100644 --- a/tests/test-leaks.lua +++ b/tests/test-leaks.lua @@ -1,5 +1,6 @@ -- Some memory leak checks as integration tests. +local runner = require("_runner") local awful = require("awful") local cairo = require("lgi").cairo local create_wibox = require("_wibox_helper").create_wibox @@ -77,6 +78,6 @@ collectable(awful.widget.tasklist(1, awful.widget.tasklist.filter.currenttags)) prepare_for_collect = emit_refresh collectable(create_wibox()) -require("_runner").run_steps({ function() return true end }) +runner.run_steps({ function() return true end }) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/test-spawn-snid.lua b/tests/test-spawn-snid.lua index 27738fc2..2aaadc08 100644 --- a/tests/test-spawn-snid.lua +++ b/tests/test-spawn-snid.lua @@ -1,5 +1,6 @@ --- Tests for spawn's startup notifications. +local runner = require("_runner") local spawn = require("awful.spawn") local manage_called, c_snid @@ -38,6 +39,6 @@ local steps = { end } -require("_runner").run_steps(steps) +runner.run_steps(steps) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/test-spawn.lua b/tests/test-spawn.lua index d2f0a1aa..63d87c15 100644 --- a/tests/test-spawn.lua +++ b/tests/test-spawn.lua @@ -1,5 +1,6 @@ --- Tests for spawn +local runner = require("_runner") local spawn = require("awful.spawn") local spawns_done = 0 @@ -63,6 +64,6 @@ local steps = { end, } -require("_runner").run_steps(steps) +runner.run_steps(steps) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 From b59b28f7161420371a4aa54915428327eb03395f Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 6 Mar 2016 10:35:49 +0100 Subject: [PATCH 2/3] Fix error handling in the keygrabber We called the keygrabber and told Lua we are expecting one return value, so Lua will always get us one return value on the Lua stack. However, when an error happens, nothing is pushed on the stack, but we still tried to pop the return value. This corrupted the Lua stack. The easiest fix is to just not ask for a return value that is not used anyway. Not adding a test for this, because the test has to cause a Lua error which the C code will then log to stderr and the test runner considers this a test failure... Fixes: https://github.com/awesomeWM/awesome/issues/735 Signed-off-by: Uli Schlachter --- event.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/event.c b/event.c index f650d52b..fc9f478a 100644 --- a/event.c +++ b/event.c @@ -660,12 +660,11 @@ event_handle_key(xcb_key_press_event_t *ev) { lua_rawgeti(L, LUA_REGISTRYINDEX, globalconf.keygrabber); - if(!luaA_dofunction(L, 3, 1)) + if(!luaA_dofunction(L, 3, 0)) { warn("Stopping keygrabber."); luaA_keygrabber_stop(L); } - lua_pop(L, 1); } } else From 2d8421730bb05179b40ce72796f8b27f407ba9d3 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 6 Mar 2016 10:43:23 +0100 Subject: [PATCH 3/3] Fix stack handling on errors for the mouse grabber This one actually uses the return value from the function (where's the consistency?!), so the code is fixed to only pop the return value if there is actually one. Signed-off-by: Uli Schlachter --- event.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/event.c b/event.c index fc9f478a..555978bf 100644 --- a/event.c +++ b/event.c @@ -122,10 +122,11 @@ event_handle_mousegrabber(int x, int y, uint16_t mask) { warn("Stopping mousegrabber."); luaA_mousegrabber_stop(L); + } else { + if(!lua_isboolean(L, -1) || !lua_toboolean(L, -1)) + luaA_mousegrabber_stop(L); + lua_pop(L, 1); /* pop returned value */ } - else if(!lua_isboolean(L, -1) || !lua_toboolean(L, -1)) - luaA_mousegrabber_stop(L); - lua_pop(L, 1); /* pop returned value */ return true; } return false;