192 Commits
Author SHA1 Message Date
Castulo Martinez 59ed44faf8 Ability to create environment with complex bundle
Normal test environments come with a minimal version of os-core
bundle by default (only one file and the tracking file). Users
also have the option of not having os-core at all with the -e
"empty" option.

This commit adds another option "-r" for creating a test environment
that includes a more complete version of the os-core bundle,
with a couple of useful files: os-release and format. This type
of bundle can be useful when working with some type of tests like
updates.
2018-08-22 09:49:43 -07:00
Otavio Pontes 5f99c841f5 packs: Download packs in parallel
Use download.c parallel download api to download packs in parallel,
the same way we do for fullfiles.

Some changes were necessary in update/slow-server test. As we are using the
parallel download api to download packs the resume  strategy is now the same
described in b07285. Because of that download resume is only enables when the
download is interrupted in the first try. So we force a download fail and a
download retry in server.py to check if swupd is trying to resume the download.
Because of this change the update/slow-server test is performing 2 retries
(first downloaded is interrupted to force a resume and the second is interrupted
because the slow-server don't support download resumes) and this adds a 30 seconds
delay to the test execution. This delay isn't going to slow down the test execution
considerably, but the ideal is in the future to support running tests with 0s
timeouts. For this reason update/slow-server is being skip when not running in
travis ci.
2018-08-21 17:04:43 -07:00
Castulo Martinez 489a11adfc Add function to create new test versions
Some tests need to have not only one but two or more versions of
the server side content (web-dir).

This commit adds a function that can be used to create these new
versions.
2018-08-21 14:13:13 -07:00
Castulo Martinez 1eaca419e0 Updating README from test library
This commit updates the README with the latest functions added to
the test library.
2018-08-21 13:21:02 -07:00
Castulo Martinez 758f2483f3 New function to modify manifests in tests
It is very common to manipulate manifests when writing tests for
swupd, so in order to make it easier for users, and less error
prone, this commit introduces a function to manipulate data from
a manifest easily.
2018-08-21 13:21:02 -07:00
Castulo Martinez 99345d2089 New function to add files to a pack
Having to manually add files to the pack's tar everytime we are
dealing with delta or zero packs is error prone since those packs
should have files in a specific path for them to be used correctly
by swupd client.

This commit introduces a function to add files to zero or delta
packs in a consistent way.
2018-08-21 13:21:02 -07:00
Castulo Martinez 7cecbd2009 Adding the global ignore list for tests
Tests that compare output with an expected output strip text in
ignore files first.

This commit adds a global ignore-list intended to be used as a
fallback for all tests.
2018-08-20 15:11:19 -07:00
Castulo Martinez 898a932315 Updating test remove-boot-file
Updating the test with the correct expected result.
2018-08-20 15:11:19 -07:00
Castulo Martinez a832dd6fd9 Fix bug removing a directory still in use
When removing a dummy bundle using the test library, the library
tries to remove bundle files and directories from the file system,
however if the directory that is being removed is not empty, it
will cause the function to exit with a non zero code.

This commit fixes the bug by adding an option for ignoring this
scenario.
2018-08-20 15:11:19 -07:00
Castulo Martinez a087f89d58 Add ability to use existing files creating bundles
When creating a bundle using the testlib functions, if the user
wants the bundle to include files, those files are generated
automatically with random content.

This commit adds the capability of specifying an existing file to
be used for the bundle by using the
"-f <file in manifest>:<file to use>" notation.
2018-08-20 15:11:19 -07:00
Castulo Martinez 60e7d43dc2 Removing unnecessary directory from test bundle
When creating a test bundle, if the user didn't select any directory,
file, or link to be added to the bundle, the bundle would add
directory /usr/bin by default so the bundle would not be totally
empty, however since the bundle also always adds the tracking file
(/usr/share/clear/bundles/"$bundle_name") to the bundle, then it is
not necessary, and actually undesired to add /usr/bin by default.

This commit removes the addition of /usr/bin by default.
2018-08-20 15:11:19 -07:00
Castulo Martinez 79cb7532a3 Adding ability to create empty test environments
Test environments have all the basic elements to test swupd-client
and one of those elements is the dummy os-core bundle created and
installed in the target-dir by default. Sometimes, the person
writing a test may need to have a completely empty test environment,
meaning with no os-core bundle.

This commit adds the capability of creating a test environment with
no os-core bundle by default, by using the -e (empty) option. The
commit also modifies the os-core bundle that is being generated by
default from having one file in /ur/bin/core to being just /core,
this way the os-core bundle is smaller and faster to be created,
which is important since it is always added by default to every
test.
2018-08-20 15:11:19 -07:00
Castulo Martinez 82fc78075b Fixing a bug creating bundles with nested dirs
When creating bundles, users get to choose if they want to include
files, directories, links or dangling links in the bundle. Whatever
choice they make, all the directories that are part of the path of
the element should be created. This wasn't happening when creating
bundles with nested directories, for example /foo/bar/baz, in this
case only dir /foo/bar/baz was being added to the manifest of the
bundle but neither /foo nor /foo/bar were being added.

This commit fixes that issue. It also adds a safety feature where
it adds a '/' in front of dirs or file when user creates a bundle
in case they forget to add it themselves so the function works
properly even in that situation. For example with something like
this "-f /foo,bar/baz"
2018-08-20 15:11:19 -07:00
Castulo Martinez 25f6589ae6 Fixing expected output in add-boot-file test
Adjusting the expected output of the test scenario. Also we no
longer need to validate it against a regex, so we can just compare
it against plain text now.
2018-08-20 15:11:19 -07:00
Castulo Martinez 2dc02e3f81 Adding usage info for set_latest_version 2018-08-20 15:11:19 -07:00
Castulo Martinez fe89f2f9c8 Updating the template for the test generator
Users can generate new tests with some default values based on a
template.

This commit updates that template so the generated file is more
useful.
2018-08-20 15:11:19 -07:00
Castulo Martinez ee9b3c348c Fixes a bug when retrieving hashes from manifests
There is an issue with the get_hash_from_manifest function where
in some cases if there are two files that share the same path,
both would be picked up.

This commit fixes the issue by being more slective when choosing
the line.
2018-08-20 15:11:19 -07:00
Castulo Martinez fadabdda9d Fix a bug when updating hashes in MoM
This commit fixes a bug when updating the hashes of manifests in
MoM. When doing this, all bundles were being removed and re-added
to the MoM using the remove_from_manifest and add_to_manifest
functions, but this was having some undesired side effects.

This commit implements the update of hashes in MoM in a different
way.
2018-08-20 15:11:19 -07:00
Castulo Martinez d9892c0336 Decrease count/size when removing from manifest
When removing a file or directory from a manifest the filecount and
contentsize in the manifest were not being decreased. Also after
removing an item from the manifest, the hash of the manifest will
change, which means the person using this function in a test needs
to remember to update the hash of the manifest in the MoM or the
test will fail because the MoM will be discarded as corrupt.

This commit decreases the values of both fields so the manifest is
still accurate after removing elements from it.
Also after removing an element from the manifest, the MoM will have
its hashes automatically updated so to release the end user from
remembering doing this.

Finally this commit include an update for a test that use the
remove_from_manifest function since it doesn't need to update hashes
in the MoM as a separate step any more.
2018-08-20 15:11:19 -07:00
Castulo Martinez dfe878d159 Allow adding bundle dependency in newer versions
With the current test library a user can create a test bundle and
then add a dependency to that bundle by adding it to the bundle's
manifest. However this only worked if there was only one version
available in the web-server.
A second issue was that after modifying the manifest the hash
in the MoM would need to be updated.

This commit allow users to create a version N, create a bundle
for version N, then create a version N+M and add a dependency to
that bundle in that new version N+M.
It also recalculate all hashes in the MoM so users writing tests
don't need to remember to update them themselves.

Finally this commit includes some updates for some tests that use
the add_dependency_to_manifest function since they don't need to
update hashes in the MoM as a separate step any more.
2018-08-20 15:11:19 -07:00
Castulo Martinez fe196094ec Changes how contentsize is read from a manifest
This commit changes the way the contentsize was being read from the
manifest, making it a little more efficient and easier to read by
replacing a piped call of cat + grep + awk, to only using awk.
It also includes a couple of changes in the comments of the
function so they are more accurate.
2018-08-20 15:11:19 -07:00
Castulo Martinez 722befea90 Export more useful variables in a test environment
The set_env_variables function exports different variables that
are dependent of a specific test environment. This commit adds a
few more variables that can be used to reduce the typing when writing
tests.
2018-08-20 15:11:19 -07:00
Patrick McCarty 67fd7f572b Fix second manpage test
Using `git diff-index` is problematic for this test, because manpages
regenerated by `make` will have a modified mtime, and `git diff-index`
(being a low-level command) does not refresh the file's mtime stored in
the index. Refreshing the mtime and other stat information stored in the
index is something that happens automatically for high-level "porcelain"
commands.

Since `git diff` will suffice for checking that no uncommitted changes
to manpages exist, use it instead.

Also, use the --exit-code option instead to see the diff output in case
of failure.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2018-08-17 14:18:35 -07:00
Patrick McCarty 7fa6cd4562 Revert "test: remove manpage test"
I root caused the issue with this test (fixed in the next commit).

This reverts commit 4faee3855f.
2018-08-17 14:18:35 -07:00
Castulo Martinez c17c3f00ce Fixes typo in write_to_protected_file function
Fixing typo: appeneded -> appended
2018-08-15 17:24:28 -07:00
Castulo Martinez 8bab78fbe4 Allow leaving a test environment for debugging
Automated tests should create its own test environment including
all needed dependencies when the test starts, and should clean up
after itself once the test is over. Sometimes when developing
these tests, they don't work as expected at first and is difficult
to figure out what the problem is if the test environment is gone.

This commit allow users to temporarily skip the removal of the test
environment so he/she can debug what the problem was by only running
the test with the DEBUG_TEST env variable set to "true".

Example: DEBUG_TEST=true bats my_test.bats
2018-08-15 17:24:28 -07:00
Castulo Martinez db746d6dd2 Adds two more assertions to testlib
This commit adds the following two assertions:
- assert_files_equal
- assert_files_not_equal

These can be used in tests for validating file equality consistently.
2018-08-15 17:24:28 -07:00
Castulo Martinez 207028be84 Fixing bug in testlib variables (missing $ char)
Some variables in the test library were missing the $ character,
whichs makes bash interpret them as strings instead of variables.
This commit fixes the variable names.
2018-08-15 17:24:28 -07:00
Castulo Martinez a64c9f8c36 Adding usage info for functions in testlib
The test library should be used to create test cases based on
modular "steps", the test library helps you build these steps,
sometimes is difficult to see what parameters a function from
testlib needs.

This commit adds usage info for every function in the test lib so
it is easier for the person writing test cases to know what parameters
the function needs, by simply executing the function name with no
parameters in the command line will show this info.
2018-08-15 17:24:28 -07:00
Castulo Martinez d9c47bb4af Print the function stack on param error in testlib
Most of the functions of the test library include some type of
parameter validation, when a function is called and one of its
parameters don't comply with the expected parameters it terminates
the whole script. This is expected, but sometimes it can be
difficult to figure out what was the function that received the
incorrect parameters in the script.

This commit adds a function that prints a stack of the function
calls so when a script is terminated it is easier to figure out
the culprit.
2018-08-15 17:24:28 -07:00
Matthew Johnson 4faee3855f test: remove manpage test
This test is unreliable and fails seemingly randomly in our CI.
Restarting our tests always makes the test pass.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2018-08-15 17:22:51 -07:00
Castulo Martinez 56d3102ed9 Adds capability of using an ignore list in tests
The test library includes many assertions intended to validate
a command's output. These assertions take the command output and
compare it against an expected output. Some of these assertions
take a literal string and others take a string with regular
expression values. However, regardless of what king of string is
being used for the expected output, there are some common lines
in the output that are usually not important and are safe to ignore.
An example would be empty lines or lines with only dots.

This commit adds the capability for those assertions to use an
ignore file to include patterns that could be ignored/removed from
the command's output before comparing it against the expected
output. Also with this commit empty lines and lines with only dots
will be ignored by default. If the assertion needs to validate an
exact output without ignoring anything in the ignore-list nor ignoring
dots and blank lines, then the --identical option can be used with
the assertion.
2018-08-07 12:47:51 -07:00
Castulo Martinez 2fcca957da Adding new assertions to the test library
This commit include two parts.

1) It adds 6 new assertions to the test library:
- assert_is_output
- assert_is_not_output
- assert_regex_is_output
- assert_regex_is_not_output
- assert_regex_in_output
- assert_regex_not_in_output

2) It migrates the tests from the following categories to use the
new library:
- completion
- hashdump
- mirror
- search

Finally this commit changes a few test cases so they use
"assert_is_output" instead of "assert_in_output", that way
we can have a tighter control of the output we want since
assert_is_output requires the whole output to match to a
specific text instead of doing a partial match.
2018-08-07 12:47:51 -07:00
Otavio Pontes 3d8c0a727d testlib: Print the output differences using diff -u
Diff -u is used in previous test library and it has an easier to read output.
2018-07-26 08:39:24 -07:00
Castulo Martinez 611c3011c2 Add remove and install bundle functions to testlib
This commit adds the following three funtions to the test library:
- install_bundle
- remove_bundle
- clean_state_dir

These functions are useful specially when the global_setup and the
global_teardown are used instead of test_setup and test_teardown.

These functions allow the user to create all of its test resources
in the global_setup and reuse those same resources throughout all
the tests in the test script. By using the global_setup and
global_teardown functions the test execution time can be greatelly
reduced.

This commit also modifies the add-rc.bats and remove-rc.bats to
leverage the global setup and teardowns to increase the execution
speed. These times were reduced as shown:
 - bundleadd_v2/add-rc.bats from 1m50.129s -> 0m20.026s
 - bundleremove_v2/remove-rc.bats from 0m59.079s -> 0m15.446s
2018-07-25 10:52:37 -07:00
Castulo Martinez ca3a68f634 Rewriting bundle-remove and check-update tests
A new test library.bash was introduced that simplifies the creation
of test environments and test objects.

This commit rewrites all existing tests from
test/functional/bundleremove and test/functional/checkupdate but this
time using the new test library.

NOTE: Once all the tests have been rewriten to use the new lib, they
can be included in the Makefile so they are run with every patch,
and the old tests can be deleted.
2018-07-25 10:52:37 -07:00
Castulo Martinez 6496182f96 Rewriting bundle-list tests with the new testlib
A new test library.bash was introduced that simplifies the creation
of test environments and test objects.

This commit rewrites all existing tests from test/functional/bundlelist
but this time using the new test library. Once all the tests have been
rewriten to use the new lib, they can be included in the Makefile so
they are run with every patch, and the  old tests can be deleted.
2018-07-25 10:52:37 -07:00
Castulo Martinez 5d788d136d Adding the last missing tests from bundleadd
This commit adds the last rewritten tests for bundle-add, these
tests are the equivalent to the ones in the bundleadd directory
but using the new test library.
2018-07-25 10:52:37 -07:00
Castulo Martinez f5aceccab3 Including documentation for the test library
This commit adds some documentation explaining how to use the test
library to create new tests and how to run them.
2018-07-25 10:52:37 -07:00
Castulo Martinez 9aecbf4715 Adding assertions to the test library
This commit adds some assertions that can be used to validate
common things in a consistent manner among tests.

The assertions added with this commit are the following:
 - assert_status_is
 - assert_status_is_not
 - assert_dir_exists
 - assert_dir_not_exists
 - assert_file_exists
 - assert_file_not_exists
 - assert_in_output
 - assert_not_in_output

More assertions may be added as needed while migrating the rest of
the tests to use the new testlib.
2018-07-25 10:52:37 -07:00
Castulo Martinez bae14b5cc7 Add functions to test lib and migrates more tests
Functions added to the testlib with this commit:
- remove_from_manifest
- get_hash_from_manifest
- remove_from_manifest
2018-07-25 10:52:37 -07:00
Castulo Martinez f515090f6a Adding function to create empty test to testlib
There is some stuff that is common for every test file, so this
commit adds a function that generates a new test file based on a
template to facilitate test creation.
2018-07-25 10:52:37 -07:00
Castulo Martinez 8e69505ceb Add new test library testlib
The old way of creating new tests require a lot of manual steps to
create the test resources needed to run the tests. This commit is
part of a series of commits to improve the workflow for creation of
new tests.

This commit introduces a new test library that aims to replace the
old swupdlib.bash library which provides many funtions to create
new test resources easily.

The following functions were added in this commit:
- generate_random_content
- generate_random_name
- validate_path
- validate_item
- validate_param
- create_dir
- create_file
- create_link
- create_tar
- create_manifest
- add_to_manifest
- create_test_environment
- destroy_test_environment
- create_bundle
- set_env_variables
- sign_manifest

The tests in bundleadd_v2 would eventually replace those in bundleadd

Related to issue #258
2018-07-25 10:52:37 -07:00
Icarus Sparry 5c2d977508 Remove the fd error message from things to ignore
We care about them now!

Signed-off-by: Icarus Sparry <icarus.w.sparry@intel.com>
2018-07-18 12:21:13 -07:00
Otavio Pontes 1764559ea5 Use strdup_or_die() instead of strdup()
Consolidate calls to abort() on out of memory errors on doing a strdup()
2018-07-13 17:34:17 -07:00
Otavio Pontes 07ae1ac8c5 download: Don't warn about files missing in packs
It's inconsistent to list just the first file missing in a pack. As
There's already a warning saying home many files are missing in
packs, remove this print.
2018-07-13 16:15:41 -07:00
Otavio Pontes cd406409f8 curl: Set fallback CA paths in swupd_curl_init()
Curl initialization were split in 2 different functions, swupd_curl_init(),
that creates the curl handles and swupd_curl_check_network() that checks the
network and set alternative CA paths, if needed.

Merging those two functions in one to perform all curl initialization all at
once.

Also fixes:
 - Fix cases where curl was used before calling swupd_curl_check_network() and
   then the correct CA path wasn't set.
 - Don't use #ifdef FALLBACK_CAPATHS because FALLBACK_CAPATHS is always defined.
   It's set to an empty string if fallback ca paths are disabled.
 - Don't use extra memory to duplicate content of FALLBACK_CAPATHS and store
   it in a global.
2018-07-13 16:15:41 -07:00
Castulo Martinez 8dcc46edb3 Removing unnecesary code to untrack bundles
Every bundle includes a tracking file which tells the OS the
bundle is installed, every bundle has this tracking file as
part of its manifest. When removing a bundle from a system,
all the files that are part of that bundle, and are not needed,
for any other bundle are removed, including the tracking file.

This patch removes a function call that is intended to remove
the tracking bundle from the system, since it is not necessary,
by the time the code calls that function, all files from the
manifest that can be removed are already removed, and this includes
the tracking file.

This patch also modifies a few tests to reflect the change in the
command output.
2018-07-10 16:08:47 -07:00
Otavio Pontes 368c504a4d test: Use different ports for tests to avoid colision
When running all tests at the same time using make -j check,
update/slow-server and check-update/slow server were trying to start
the slow server at the same port.
2018-07-04 07:03:53 -07:00
Otavio Pontes 6c03e883f3 test: Remove debug leftovers 2018-06-14 13:04:31 -07:00