29 Commits

Author SHA1 Message Date
Zeyad Yasser
3c541e7183 tests: kill process in interface-process-control as early as possible (#13973)
Cleaning (killing) the spawned process was deferred to restore but spread
waits for execute script to finish completely which causes the test to hang
for the whole time of the process (sleep 5m).

If the test is successful we could speed up the process by popping the
clean command.

Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>
2024-05-27 21:23:23 +03:00
Maciej Borzecki
e3ab724999 tests/main/interfaces-process-control: retry check for process being terminated
We are sending a SIGTERM to the test process, and so its handling and test
process termination is asynchronous and there is no guarantee the test process
exits immediately. Retry the check a couple of times to account for this.

The problem was often seen to happen on openSUSE:

Error: 2024-01-17 21:36:40 Error executing google:opensuse-tumbleweed-64:tests/main/interfaces-process-control (jan172104-345478) :
-----
+ echo 'The interface is disconnected by default'
The interface is disconnected by default
+ snap interfaces -i process-control
+ MATCH -- '- +process-control-consumer:process-control'

'snap interfaces' is deprecated; use 'snap connections'.
+ echo 'When the plug is connected'
When the plug is connected
+ snap connect process-control-consumer:process-control
+ echo 'Then the snap is able to kill an existing process'
Then the snap is able to kill an existing process
+ pid=31252
+ sleep 5m
+ kill -s 0 31252
+ process-control-consumer.signal SIGTERM 31252
+ not kill -s 0 31252
-----

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
2024-01-19 10:40:09 +01:00
Sergio Cazzolato
1050c92659 tests: improve interface-process-control test (#12611)
* Improve interface-process-control test

The test is failing in ubuntu lunar doing the pid cleanup, which is not
testing any snapd feature.

This change makes sure the pid is killed during the restare fase, even
when the execute check fails.

* Update tests/main/interfaces-process-control/task.yaml

Co-authored-by: Philip Meulengracht <the_meulengracht@hotmail.com>

* Check if the process is still alive

---------

Co-authored-by: Philip Meulengracht <the_meulengracht@hotmail.com>
2023-03-06 16:27:43 +01:00
Sergio Cazzolato
ebe85ba8a3 Moving to tests directories snaps built locally - part 1
Script being used to detect which snaps can be moved to

for snap in $(ls tests/lib/snaps); do
    count=0
    last=
    for test in $(find tests/ -name task.yaml); do
    	if $(grep -q $snap $test); then
    	    count=$((count+1))
    	    last=$test
    	fi
    done
    echo "$snap -> $count times"
    if [ $count = 1 ]; then
	echo "mv tests/lib/snaps/$snap $(dirname $last)"
    fi
done
2021-04-22 16:49:33 -03:00
Sergio Cazzolato
9087d184db Update layout for tests - part 1
The change updates the layout of the tests following a proposed order
which should make the test easier to read and understand

The proposed order is:

summary
details

backends
systems

manual
priority
warn-timout
kill-timeout

environment
prepare
restore
debug
execute
2021-04-08 15:05:29 -03:00
Sergio Cazzolato
a6e8691e0b Moving main suite to snaps-state tool part 4 2020-10-01 12:00:46 -03:00
Zygmunt Krynicki
6600bdeeed tests: check for pids correctly.
Using grep for PIDs is easy to do incorrectly, as we've found out the
hard way when a test searching for pid 2499 found process 24998. Rewrite
that part of the test to use kill with signal zero as a much safer and
less magic way of doing the same thing.

As a drive-by fix a typo in the description and remove useless sleep
loops. One sleep of moderate duration is sufficient.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
2020-07-20 11:20:21 +02:00
Zygmunt Krynicki
368fd6c646 tests: replace "! foo | ... | bar" with "not foo | ... | bar"
This patch replaces more complex negated commands, those involving pipes
with the help of the two sed expressions:

    find -name 'task.yaml' -exec sed -i -E -e 's/^( *)! *(.?+) +\| *([^|]+[^\]$)/\1\2 | not \3/' {} \;
    find -name 'task.yaml' -exec sed -i -E -e 's/^( *)! *(.?+) *\| *([^|]+[^\]$)/\1\2 | not \3/' {} \;

The two commands are almost identical, differing in only the approach
towards white-space before the pipe operator. This was done because sed
doesn't natively support non-greedy expressions and I wanted the output
to have consistent spacing.

It is worth noting that the expression excludes commands that have a
continuation on the following line, since those would not be handled
correctly. As a simple example:

    ! foo | bar \
    | froz

The diff was rather uneventful but one replacement result was manually
left out, because it had matched a command like "! foo || bar". Such
exceptions are not worth encoding in the automation since they occur
very infrequently in our code.

Please see the previous commit for a discussion on why pipes need to be
handled this way.

Signed-off-by: Zygmunt Krynicki <me@zygoon.pl>
2019-05-29 10:44:09 +02:00
Sergio Cazzolato
9aaaa933ec Remove PWD use and normalize interfaces tests 2019-01-22 18:18:15 -03:00
Sergio Cazzolato
50c7e1a92e Auto-clean the test directory 2019-01-14 23:42:55 -03:00
Maciej Borzecki
083e1f4459 tests: shellchecks part 5
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2018-07-31 15:05:35 +02:00
sergio-j-cazzolato
90c6f913fa Checking interfaces declaring the specific interface
This is done in the tests which are checking the interfaces information
in order to make them more robusts, making the test independent of other
plug:slots declared such it is happening in gadgets.
2018-04-24 08:59:15 -03:00
sergio-j-cazzolato
20c8ab9e1c Update interface tests to remove extra checks and normalize tests
This change includes:
. Remove all the checks that are done after a connection and
disconnection (this is already checked as part of the snap_connect and
snap_disconnect tests).
. install_local function used to pack and install local snaps
. Remove not needed echo
. Change the check of interfaces default behaviour for the
autoconnection to support the scenario when there are other snaps also
connected to the interface (that happens when testing caracalla gadget)
. Add new lines between task tags
2018-02-22 11:30:19 -03:00
Michael Vogt
aa08253052 snap: add new snap pack and use in tests (#3951)
* snap: add new `snap pack` and use in tests

* address first review feedback

* tests/upgrade/basic: skip classic test if "snap pack" missing
2017-10-09 16:46:19 +01:00
Zygmunt Krynicki
89729aa992 daemon: rename "none" confinement to "partial"
There is no way to have "no" confinement as many backends are used
at all times. The names should reflect this.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
2017-07-06 14:45:17 +02:00
Simon Fels
70395d5117 tests/main: switch checks for strict and none 2017-05-19 11:37:08 +02:00
Simon Fels
c30cb77bad tests/main: use new confinement debug command 2017-05-19 09:08:01 +02:00
Simon Fels
26da526364 tests/main: drop warning message for missing confinement 2017-05-19 07:36:39 +02:00
Simon Fels
a7d112bc81 tests/main: convert all remaining tests to use forced-devmode switch 2017-05-11 12:26:39 +02:00
Simon Fels
fbf1452c05 many: move forced-devmode check into daemon and return error 2017-05-11 12:26:39 +02:00
Simon Fels
900ffc4dd1 tests/main: use forced-devmode check instead of system blacklisting 2017-05-11 12:26:39 +02:00
Simon Fels
47010448db tests: describe why certain tests are disabled 2017-04-27 11:07:32 +02:00
Simon Fels
77ef0cb000 tests: blacklist test cases not applicable for debian systems
Those test case will be reworked in a second phase to properly check
for confinement support and mark themself as not applicable.
2017-04-27 11:06:34 +02:00
Federico Gimenez
293f00418f remove core_name variable 2017-03-09 17:45:30 +01:00
John Lenton
1b99de325f all: use "core" by default but allow "ubuntu-core" still (#2070) 2016-10-04 13:15:32 -03:00