Rahix / tbot

Automation/Testing tool for Embedded Linux Development
https://tbot.tools
GNU General Public License v3.0
84 stars 21 forks source link

Add use_cache parameter to check_for_tool() and hashcmp() #83

Closed jneuhauser closed 1 year ago

jneuhauser commented 1 year ago

Hello @Rahix,

we have some test cases where we use hashcmp() excessively to ensure the device under test is in shape. Add the parameter use_cache, which defaults to False, for optional cached results.

In the same test, we use check_for_tool() to determine if some executables/scripts need to be deployed first, but since the result of check_for_tool() is cached, we still always get False from check_for_tool() after a successful deployment. Add the parameter use_cache, which defaults to True, to optionally disable cached results.

I have implemented the default values for use_cache to keep the old behavior of check_for_tool() and hashcmp().

Greets, Johann

Rahix commented 1 year ago

(I am aware of the CI failures, ignore them for now. I'll dig into it and let you know once I've fixed it in master so you can rebase.)

jneuhauser commented 1 year ago

Do you think something similar to the copy_if_outdated() would be useful for you or not?

We also have boards that don't have ethernet and so no ssh/scp is possible.

It could definitely be useful for my use case in the future, but currently the function shown above wouldn't do it for me since copy() doesn't have support for serial console transfer yet.

However, I have already planned to extend copy() to support serial console transmission so that I can simplify my downstream implementation of copy_if_outdated().

Rahix commented 1 year ago

However, I have already planned to extend copy() to support serial console transmission

Yeah, I always wanted that as well. However, I ran into so many things I want to do before that(tm) that I didn't reach it yet. So maybe I can share my thoughts here:

Of course the easiest implementation is actually quite straight forward:

content = file_src.read_bytes()
file_dest.write_bytes(content)

This implementation has a few problems, though:

  1. It only works when both hosts have the base64 utility available which surprisingly isn't the case for a lot of embedded Linux systems. So I want to extend {read,write}_bytes() to fall back to other tools when base64 is missing. I do not yet know which alternative tools would be the best options here, though.
  2. Next, it clutters the tbot console a lot with uninteresting data. I've taken care that {read,write}_bytes() don't produce completely ugly terminal output but it still isn't pleasant when you don't care about the contents. Ideally, we would hide the output from the two commands when running under copy(). A facility for that exists now, in the form of tbot.log.with_verbosity(). Ideally, I wanted to overhaul the entire logging first, but I think that helper is a good enough start for now.
Rahix commented 1 year ago

On that note, I just pushed 4d385785c249 ("log: Add only_decrease parameter to with_verbosity()") which may be useful for my point 2.