As noted in [1], some work needs to be done before we can start writing tests for lshw.
Currently, lshw's functionality can be roughly explained as follows:
- the file src/lshw.cc examines all the command line arguments
- After setting up variables determining the information that is going to be
printed, the function scan_system() is called, which is defined in src/core/main.cc
- This function, depending on what information has been requested for, calls
functions defined in various files - such as cpuinfo.cc for CPU info, mem.cc for memory
information and so on which return the requested info.
- These files read their data from /proc and /sys and then return the data after filling
those
in the appropriate data structure. As mentioned in [1], not all reads their data from
procfs
and sys. For example, those which fetch disk information do it via ioctl() calls.
However, as of
now, we may ignore the disk related functionality of lshw, since we use libparted for
that now.
So, we want that instead of reading these data from the live systems, when run as part
of the test suite, lshw should ready them from our test data - a snapshot of relevant
files from
procfs and sysfs.
One approach that I can think of is:
- Add an extra option to lshw -s specifying the location of the snapshot
- When this is set, we can set an environment variable to point
to the location of the snapshot. In all the files where the information
is read from the file systems, before opening the file, we check
for this environment variable, and if it exists, we read the files from there instead.
And of course, matching the expected output, etc follows after that.
Would be interested in any feedback.
Thanks,
Amit.
[1]
https://bugzilla.redhat.com/show_bug.cgi?id=986157
--
Amit Saha <
http://echorand.me>
Infrastructure Engineering and Development
Red Hat, Inc.