From 54dd973e3feb3624314e91806f836e7528c3eb46 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 1 Jan 2017 14:18:59 +0100 Subject: [PATCH 1/9] Add awesome.sync() This function should only be necessary for the test suite. It makes sure that the X11 server received and handled all previous requests that awesome sent. This will be needed, for example, in tests that use root.fake_input(). After a call to awesome.sync(), we are sure that "faking input" has been done and the next main loop iteration will handle the input event. Without the sync, it could happen that the X11 server did not yet fake the input in the next iteration. Signed-off-by: Uli Schlachter --- luaa.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/luaa.c b/luaa.c index e5cd0556..332105d1 100644 --- a/luaa.c +++ b/luaa.c @@ -54,6 +54,7 @@ #include #include +#include #include /* for gethostname() */ @@ -214,6 +215,17 @@ luaA_kill(lua_State *L) return 1; } +/** Synchronize with the X11 server. This is needed in the test suite to avoid + * some race conditions. You should never need to use this function. + * @function sync + */ +static int +luaA_sync(lua_State *L) +{ + xcb_aux_sync(globalconf.connection); + return 0; +} + /** Load an image from a given path. * * @param name The file name. @@ -647,6 +659,7 @@ luaA_init(xdgHandle* xdg, string_array_t *searchpath) { "xkb_get_group_names", luaA_xkb_get_group_names}, { "xrdb_get_value", luaA_xrdb_get_value}, { "kill", luaA_kill}, + { "sync", luaA_sync}, { NULL, NULL } }; From 5bbe6747fc30e3fe00afe85795fa31819ebc5bde Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 1 Jan 2017 14:22:36 +0100 Subject: [PATCH 2/9] tests: Add calls to awesome.sync() where needed Signed-off-by: Uli Schlachter --- tests/test-awesomerc.lua | 5 +++++ tests/test-awful-widget-button.lua | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/test-awesomerc.lua b/tests/test-awesomerc.lua index 9e88f955..8af7d9aa 100644 --- a/tests/test-awesomerc.lua +++ b/tests/test-awesomerc.lua @@ -58,6 +58,7 @@ local steps = { assert(not old_c.ontop) get_callback({modkey}, "t")() + awesome.sync() return true end, @@ -75,6 +76,7 @@ local steps = { assert(t.master_width_factor == 0.5) get_callback({modkey}, "l")() + awesome.sync() return true end, @@ -89,6 +91,7 @@ local steps = { assert(t.master_count == 1) get_callback({modkey, "Shift"}, "h")() + awesome.sync() return true end, @@ -104,6 +107,7 @@ local steps = { get_callback({modkey, "Control"}, "h")() get_callback({modkey, "Shift" }, "l")() + awesome.sync() return true end, @@ -118,6 +122,7 @@ local steps = { assert(t.index == 1) get_callback({modkey, }, "Right")() + awesome.sync() return true end, diff --git a/tests/test-awful-widget-button.lua b/tests/test-awful-widget-button.lua index b7051547..f6cd2c5a 100644 --- a/tests/test-awful-widget-button.lua +++ b/tests/test-awful-widget-button.lua @@ -82,6 +82,7 @@ table.insert(steps, function() awful.placement.centered(mouse) root.fake_input("button_press", 1) + awesome.sync() return true end) @@ -94,10 +95,11 @@ end) -- Test a button release table.insert(steps, function() - root.fake_input("button_release", 1) - assert(button._private.image ~= img) + root.fake_input("button_release", 1) + awesome.sync() + return true end) @@ -106,6 +108,7 @@ table.insert(steps, function() assert(button._private.image == img) root.fake_input("button_press", 1) + awesome.sync() return true end) @@ -123,6 +126,7 @@ assert(button._private.image ~= img) -- test if the button is released when the mouse move out awful.placement.right(mouse--[[, {parent = w}]]) root.fake_input("button_release", 1) +awesome.sync() return true end) From 0dff0c308ae6cada5537ded951bc807665813fe0 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 1 Jan 2017 14:29:04 +0100 Subject: [PATCH 3/9] test-geometry.lua: Fix indentation Signed-off-by: Uli Schlachter --- tests/test-geometry.lua | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/test-geometry.lua b/tests/test-geometry.lua index 7b6bf19c..12535d2b 100644 --- a/tests/test-geometry.lua +++ b/tests/test-geometry.lua @@ -55,18 +55,17 @@ local steps = { awful.rules.rules = { -- All clients will match this rule. { rule = { },properties = { - titlebars_enabled = true, - border_width = 10, - border_color = "#00ff00", - size_hints_honor = false, - x = 0, - y = 0, - width = 100, - height = 100 + titlebars_enabled = true, + border_width = 10, + border_color = "#00ff00", + size_hints_honor = false, + x = 0, + y = 0, + width = 100, + height = 100 + }} } - } -} -return true + return true end, function(count) if count == 1 then From 0d8106c6dda0d5decb01ff0e74ff27fd5006a844 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 1 Jan 2017 14:30:17 +0100 Subject: [PATCH 4/9] test-leak-client.lua: Wait for c:kill() to be done Signed-off-by: Uli Schlachter --- tests/test-leak-client.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-leak-client.lua b/tests/test-leak-client.lua index 09e2d290..edba1ef5 100644 --- a/tests/test-leak-client.lua +++ b/tests/test-leak-client.lua @@ -62,7 +62,7 @@ local steps = { -- Wait for one iteration so that gears.timer handles other delayed -- calls (= the tasklist updates) second_call = true - else + elseif #client.get() == 0 then assert(#objs == 1) -- Test that we have a client and that it's invalid (tostring() From 30912c6f24bb7020ecbb4f90621234dcb6b9518a Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 1 Jan 2017 14:31:08 +0100 Subject: [PATCH 5/9] test-geometry: Wait for c:kill() to be done Signed-off-by: Uli Schlachter --- tests/test-geometry.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test-geometry.lua b/tests/test-geometry.lua index 12535d2b..c90d1b9d 100644 --- a/tests/test-geometry.lua +++ b/tests/test-geometry.lua @@ -65,7 +65,10 @@ local steps = { height = 100 }} } - return true + -- Wait for the previous c:kill() to be done + if #client.get() == 0 then + return true + end end, function(count) if count == 1 then From a1b5782e90507ebfc0bfe4eee0ea2a7617ef46c1 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 1 Jan 2017 14:33:13 +0100 Subject: [PATCH 6/9] test-awful-client.lua: Wait for c:kill() to be done Signed-off-by: Uli Schlachter --- tests/test-awful-client.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test-awful-client.lua b/tests/test-awful-client.lua index 86ba0433..90da7f0b 100644 --- a/tests/test-awful-client.lua +++ b/tests/test-awful-client.lua @@ -214,7 +214,12 @@ table.insert(multi_screen_steps, function() for _, c in ipairs(client.get()) do c:kill() end + if #client.get() == 0 then + return true + end +end) +table.insert(multi_screen_steps, function() for i=1, screen.count() do local s = screen[i] test_client("screen"..i, nil, { @@ -240,6 +245,16 @@ end for _, c in ipairs(client.get()) do c:kill() end +return true +end) + +table.insert(multi_screen_steps, function() +if #client.get() == 0 then + return true +end +end) + +table.insert(multi_screen_steps, function() if screen.count() < 2 then return true end From edff48f133a07d93fbc5a3abbd6319538bdd1dee Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 1 Jan 2017 14:34:18 +0100 Subject: [PATCH 7/9] test-awful-client.lua: Fix indentation Signed-off-by: Uli Schlachter --- tests/test-awful-client.lua | 138 ++++++++++++++++++------------------ 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/tests/test-awful-client.lua b/tests/test-awful-client.lua index 90da7f0b..deab7f4e 100644 --- a/tests/test-awful-client.lua +++ b/tests/test-awful-client.lua @@ -108,21 +108,21 @@ table.insert(steps, function() end) table.insert(steps, function() --- The request should have been denied -assert(client.focus == c2) + -- The request should have been denied + assert(client.focus == c2) --- Test the remove function -awful.ewmh.remove_activate_filter(function() end) + -- Test the remove function + awful.ewmh.remove_activate_filter(function() end) -awful.ewmh.add_activate_filter(awful.ewmh.generic_activate_filters[1]) + awful.ewmh.add_activate_filter(awful.ewmh.generic_activate_filters[1]) -awful.ewmh.remove_activate_filter(awful.ewmh.generic_activate_filters[1]) + awful.ewmh.remove_activate_filter(awful.ewmh.generic_activate_filters[1]) -assert(original_count == #awful.ewmh.generic_activate_filters) + assert(original_count == #awful.ewmh.generic_activate_filters) -c1:emit_signal("request::activate", "i_said_so") + c1:emit_signal("request::activate", "i_said_so") -return client.focus == c1 + return client.focus == c1 end) local has_error @@ -234,91 +234,91 @@ table.insert(multi_screen_steps, function() end) table.insert(multi_screen_steps, function() -if #client.get() ~= screen.count() then return end + if #client.get() ~= screen.count() then return end -for _, c in ipairs(client.get()) do - assert(#c:tags() == 1) - assert(c.first_tag.name == "NEW_AT_"..c.screen.index) -end + for _, c in ipairs(client.get()) do + assert(#c:tags() == 1) + assert(c.first_tag.name == "NEW_AT_"..c.screen.index) + end --- Kill the client -for _, c in ipairs(client.get()) do - c:kill() -end -return true -end) - -table.insert(multi_screen_steps, function() -if #client.get() == 0 then + -- Kill the client + for _, c in ipairs(client.get()) do + c:kill() + end return true -end +end) + +table.insert(multi_screen_steps, function() + if #client.get() == 0 then + return true + end end) table.insert(multi_screen_steps, function() -if screen.count() < 2 then return true end + if screen.count() < 2 then return true end --- Now, add client where the target tag and screen don't match -test_client("test_tag1", nil, { - tag = screen[2].tags[2], - screen = screen[1], - }) + -- Now, add client where the target tag and screen don't match + test_client("test_tag1", nil, { + tag = screen[2].tags[2], + screen = screen[1], + }) --- Add a client with multiple tags on the same screen, but not c.screen -test_client("test_tags1", nil, { - tags = { screen[1].tags[3], screen[1].tags[4] }, - screen = screen[2], - }) + -- Add a client with multiple tags on the same screen, but not c.screen + test_client("test_tags1", nil, { + tags = { screen[1].tags[3], screen[1].tags[4] }, + screen = screen[2], + }) --- Identical, but using the tag names -test_client("test_tags2", nil, { - tags = { "3", "4" }, - screen = screen[2], - }) + -- Identical, but using the tag names + test_client("test_tags2", nil, { + tags = { "3", "4" }, + screen = screen[2], + }) --- Also test tags, but with an invalid screen array -test_client("test_tags3", nil, { - tags = { screen[2].tags[3], screen[1].tags[4] }, - screen = screen[1], - }) + -- Also test tags, but with an invalid screen array + test_client("test_tags3", nil, { + tags = { screen[2].tags[3], screen[1].tags[4] }, + screen = screen[1], + }) --- Another test for tags, but with no matching names -test_client("test_tags4", nil, { - tags = { "foobar", "bobcat" }, - screen = screen[1], - }) + -- Another test for tags, but with no matching names + test_client("test_tags4", nil, { + tags = { "foobar", "bobcat" }, + screen = screen[1], + }) -return true + return true end) table.insert(multi_screen_steps, function() -if screen.count() < 2 then return true end -if #client.get() ~= 5 then return end + if screen.count() < 2 then return true end + if #client.get() ~= 5 then return end -local c_by_class = {} + local c_by_class = {} -for _, c in ipairs(client.get()) do - c_by_class[c.class] = c -end + for _, c in ipairs(client.get()) do + c_by_class[c.class] = c + end -assert(c_by_class["test_tag1"].screen == screen[2]) -assert(#c_by_class["test_tag1"]:tags() == 1) + assert(c_by_class["test_tag1"].screen == screen[2]) + assert(#c_by_class["test_tag1"]:tags() == 1) -assert(c_by_class["test_tags1"].screen == screen[1]) -assert(#c_by_class["test_tags1"]:tags() == 2) + assert(c_by_class["test_tags1"].screen == screen[1]) + assert(#c_by_class["test_tags1"]:tags() == 2) -assert(c_by_class["test_tags2"].screen == screen[2]) -assert(#c_by_class["test_tags2"]:tags() == 2) + assert(c_by_class["test_tags2"].screen == screen[2]) + assert(#c_by_class["test_tags2"]:tags() == 2) -assert(c_by_class["test_tags3"].screen == screen[2]) -assert(#c_by_class["test_tags3"]:tags() == 1) + assert(c_by_class["test_tags3"].screen == screen[2]) + assert(#c_by_class["test_tags3"]:tags() == 1) -assert(c_by_class["test_tags4"].screen == screen[1]) -assert(#c_by_class["test_tags4"]:tags() == 1) -assert(c_by_class["test_tags4"]:tags()[1] == screen[1].selected_tag) + assert(c_by_class["test_tags4"].screen == screen[1]) + assert(#c_by_class["test_tags4"]:tags() == 1) + assert(c_by_class["test_tags4"]:tags()[1] == screen[1].selected_tag) -return true + return true end) require("_multi_screen")(steps, multi_screen_steps) From 6534208f62b084fc7fa0c2973d74a212c1d4ae40 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 1 Jan 2017 14:46:29 +0100 Subject: [PATCH 8/9] tests/_runner.lua: Use less waiting Before this, the test runner used a timer which fired every 0.1 seconds to "do its thing". Many of these waits seem unnecessary. This commit makes the test runner wait 0 seconds for the first call of a step function. Only following calls will have a timeout of 0.1 seconds applied. A full run of the test suite (tests/run.sh without further arguments) took about 100 seconds before this change. After this change, we are down to 60 seconds. This is almost factor two faster! (Well, five thirds is the exact number, so factor 1.66) (The numbers are best out of three runs. The "before" number is rounded down while the "after" number is rounded up.) Signed-off-by: Uli Schlachter --- tests/_runner.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/_runner.lua b/tests/_runner.lua index c446c04b..5d5b4810 100644 --- a/tests/_runner.lua +++ b/tests/_runner.lua @@ -32,7 +32,7 @@ end) runner.run_steps = function(steps) -- Setup timer/timeout to limit waiting for signal and quitting awesome. -- This would be common for all tests. - local t = timer({timeout=0.1}) + local t = timer({timeout=0}) local wait=20 local step=1 local step_count=0 @@ -64,6 +64,7 @@ runner.run_steps = function(steps) step = step+1 step_count = 0 wait = 5 + t.timeout = 0 t:again() return end @@ -78,6 +79,7 @@ runner.run_steps = function(steps) else wait = wait-1 if wait > 0 then + t.timeout = 0.1 t:again() else io.stderr:write("Error: timeout waiting for signal in step " From f7025e2f731a29ab44309c01c05fef646f170ceb Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 1 Jan 2017 14:51:39 +0100 Subject: [PATCH 9/9] Fix tests/run.sh Commit a944636c0281314ef "bashified" tests/run.sh for some reason. Afterwards, commit 4abd820051d3e4b09d fixed some of the fall-out. However, there is still a problem left. We have "set -e" in this script. Thus, whenever some command exits with status 0, the script abort. When the variable errors is zero/unset, the command "((errors++))" has exit status zero. Thus, this instruction caused the shell script to abort. This was not intended. Fix this by using "((++errors))" instead. Signed-off-by: Uli Schlachter --- tests/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run.sh b/tests/run.sh index 24caf274..64f3f941 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -228,7 +228,7 @@ for f in $tests; do grep -q -E '[Ee]rror|assertion failed' "$awesome_log"; then echo "===> ERROR running $f <===" grep --color -o --binary-files=text -E '.*[Ee]rror.*|.*assertion failed.*' "$awesome_log" || true - ((errors++)) + ((++errors)) fi done