Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve test scripts #44

Closed
wants to merge 2 commits into from
Closed

improve test scripts #44

wants to merge 2 commits into from

Conversation

zimbatm
Copy link
Member

@zimbatm zimbatm commented Dec 25, 2017

  • validated with shellcheck
  • allow to evaluate just one for convenience
  • reduce verbosity and improve debugging output

* validated with shellcheck
* allow to evaluate just one for convenience
* reduce verbosity and improve debugging output
@zimbatm zimbatm mentioned this pull request Dec 25, 2017
2 tasks
Copy link
Member

@lukateras lukateras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zimbatm, I really appreciate that you made Travis CI to work, and I do appreciate the time you've spent on doing this, but...

This turns a 15-line shell script into 45 lines without much return.

It hides useful information (list of derivations that will be built might be useful, e.g. it might help debug stuck builds). CI logs should be as verbose as possible. When my local checks stutter with download-from-binary-cache.pl, I also want to know that.

It introduces a checker that has to be babysitted by adding magical comments and makes the script much harder to change without causing subsequent checks to fail (see NixOS/nixpkgs#32857).

It also includes redundant formatting that mostly duplicates what is currently being emitted by the script or by nix-build command.

I think this is over-engineered out of proportion and what we currently have (roughly, your second rebase of #40) is close to being ideal, other than missing --show-trace.

@@ -0,0 +1,35 @@
#!/bin/sh
Copy link
Member

@lukateras lukateras Dec 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Evaluating just one is not a proper test, because profiles can be inherited (even model profiles, because there might be revisions, e.g. later revisions of X220 do not support tp_smapi).

It can be done via nixos-rebuild -I nixos-config=tests/eval-test.nix nixos-hardware-config=path/to/default.nix dry-build. I think it's a bad idea to allow to eval just one profile via a script.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Travis will evaluate all of them in the end, or not?

Copy link
Member

@lukateras lukateras Dec 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Travis evaluates every profile on each push or pull request.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here is that I can test my profile without having to wait on all the others to evaluate. Travis is testing all the profiles anyways.

Copy link
Member

@lukateras lukateras Dec 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't assume that your profile isn't inherited by any other profiles. Profile might be inherited by someone from another directory, e.g. in case of brand renaming (e.g. IBM ThinkPad -> Lenovo ThinkPad), including a model profile.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this relevant? Travis will catch this eventually.

Copy link
Member

@lukateras lukateras Dec 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's relevant in that it's not a test and thus should not be exposed. It's possible to see someone with merge rights using eval-one test for convenience and then pushing to master.

Actually, doing that is the only use case I can come up with in regards to this script.

@@ -1,15 +1,11 @@
#!/bin/sh
set -efu
cd "$(dirname "$0")/.." || exit 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't really fail.

Copy link
Member

@Mic92 Mic92 Dec 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

|| exit 1 should not be necessary, since set -e is used.

ret=$?

if [ "$ret" -gt 0 ]; then
echo ERROR
Copy link
Member

@lukateras lukateras Dec 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nix-build already prints "error", we don't need to print that twice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at the Travis CI output logs and you will understand.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-I "nixos-config=$here/eval-test.nix" \
-I "nixos-hardware-profile=$profile" \
--dry-run \
--no-out-link \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--no-out-link doesn't do anything when --dry-run is present.

nix-build \
'<nixpkgs/nixos>' \
-I "nixos-config=$here/eval-test.nix" \
-I "nixos-hardware-profile=$profile" \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't allow profiles that have spaces in names.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't hurt to escape the argument in either case

Copy link
Member

@lukateras lukateras Dec 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does. We should enforce that there are no spaces in names.

--dry-run \
--no-out-link \
--show-trace \
-A system > "$logfile" 2>&1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the point of having a log file instead of stderr, and I think it hides a lot of potentially useful information. Also, the idea of stderr is exactly to have an error log.

Copy link
Member

@Mic92 Mic92 Dec 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test will only produce output when the test fail and will output both stdout and stderr. This sounds good to me.

Copy link
Member

@lukateras lukateras Dec 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't matter, I think nix-build only ever writes to stderr. What matters is that sometimes CI builds may stutter, and with this approach, we'll never know why.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also 2>&1 is a bashism.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yegortimoshenko With this approach it's easy to find the failing profile and get to the point instead of going through pages of repeating out links. They might be interesting but not very useful in practice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, you only need logs if something goes wrong. Your way of doing things makes certain errors opaque and non-debuggable.

set -e

cd "$(dirname "$0")/.."
echo "### Evaluating all profiles ###"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant.

profile=$1
logfile=$(mktemp)

# shellcheck disable=SC2039
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of using a tool when it requires magic comments to do its job? I think shellcheck is very overreaching, and we shouldn't use it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It catches a lot of common mistakes and educates the users about shell corner-cases.

Copy link
Member

@lukateras lukateras Dec 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need that for fifteen lines of shell script. And teaching people to use something doesn't make magical comments OK.

-I "nixos-hardware-profile=$profile" \
--dry-run \
--no-out-link \
--show-trace \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--show-trace might be useful and should make it into master.


# shellcheck disable=SC2044
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why you ignore this check: https://github.com/koalaman/shellcheck/wiki/SC2044

In this case, it could be rewritten as find . -name default.nix -exec tests/eval-one.sh {}. But again, I think we shouldn't accept files with weird names into this repo, and current shell script makes sure that we won't.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no solution that doesn't depend on word splitting, without depending on bash 4. find -exec doesn't early-return nor propagate the exit status. I don't think that profiles should contain special characters in any case.

lukateras added a commit that referenced this pull request Dec 25, 2017
@@ -1,15 +1,11 @@
#!/bin/sh
set -efu
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set -o pipefail also comes handy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a bashism.

@lukateras
Copy link
Member

Resolved in #66 with a fundamentally different approach.

@lukateras lukateras closed this Jul 17, 2018
@lukateras
Copy link
Member

lukateras commented Nov 2, 2018

@zimbatm I shouldn't have behaved so aggressively over this. I'm sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants