hwlib-0.10.0/.cargo_vcs_info.json0000644000000001440000000000100122160ustar { "git": { "sha1": "6b8eaf2d955cdffc4b69d292bce0a98e6eecc19e" }, "path_in_vcs": "client" }hwlib-0.10.0/.gitignore000064400000000000000000000003451046102023000130010ustar 00000000000000target cargo_home .cargo-checksum.json __pycache__/ # In a workspace, packages should share the same Cargo.lock file. # See https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html for more hwlib/Cargo.lock hwctl/Cargo.lock hwlib-0.10.0/CONTRIBUTING.md000064400000000000000000000044621046102023000132460ustar 00000000000000# Contributing to the Hardware API Client This document provides the information needed to contribute to the Hardware API Client. For basic usage of the `hardware-api` client, refer to the client [readme](./README.md). For general contribution guidelines for the `hardware-api` project, refer to the [contribution guide](../CONTRIBUTING.md). ## Snap Package `hwctl` is packaged as a [snap]. To build the snap package locally, install [`snapcraft`][snapcraft] and run the following command: ```shell snapcraft pack ``` The above command will create a file in the form of `hwctl__.snap`. To install the snap locally, run the following command: ```shell sudo snap install --dangerous hwctl__.snap # The following interfaces are required to run the snap package # They are not automatically connected when installing a local package sudo snap connect hwctl:hardware-observe sudo snap connect hwctl:kenrel-module-observe sudo snap connect hwctl:system-observe ``` ## Use Python Bindings The `hwlib` library can be used in Python code as well. We're using the [`pyo3`][pyo3] library to create Python bindings; to build them, you need to have [`maturin`][maturin] installed on your system. It requires a virtual environment to be configured to work with it: ```shell virtualenv venv source venv/bin/activate pip install maturin ``` Then run the following commands: ```shell cd hwlib maturin develop ``` Now you can use the library in your Python code. The library requires root access since we collect the hardware information using SMBIOS data. If you're running it on a device that doesn't have SMBIOS data available, root privileges are not required. ```python $ sudo /path/to/venv/bin/python3 # or `python3` >>> import hwlib >>> hwlib.get_certification_status("https://hw.ubuntu.com") ``` ## Test Since we're using Python bindings, this library contains tests for both Rust and Python code. To execute them, run the following commands: - Run Rust tests: `$ cargo test` - Run Python tests: You need to have [`tox`][tox] (`pip install tox`). Then you can run Python tests with `$ tox` [snap]: https://snapcraft.io/hwctl [snapcraft]: https://github.com/canonical/snapcraft [pyo3]: https://github.com/PyO3/pyo3 [maturin]: https://github.com/PyO3/maturin [tox]: https://github.com/tox-dev/tox hwlib-0.10.0/Cargo.lock0000644000000524730000000000100102050ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 4 [[package]] name = "anstream" version = "0.6.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", "is_terminal_polyfill", "utf8parse", ] [[package]] name = "anstyle" version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" [[package]] name = "anstyle-parse" version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2" dependencies = [ "windows-sys 0.60.2", ] [[package]] name = "anstyle-wincon" version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a" dependencies = [ "anstyle", "once_cell_polyfill", "windows-sys 0.60.2", ] [[package]] name = "anyhow" version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" [[package]] name = "autocfg" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "bitflags" version = "2.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" [[package]] name = "cc" version = "1.2.41" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac9fe6cdbb24b6ade63616c0a0688e45bb56732262c158df3c0c4bea4ca47cb7" dependencies = [ "find-msvc-tools", "shlex", ] [[package]] name = "cfg-if" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "clap" version = "4.5.49" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4512b90fa68d3a9932cea5184017c5d200f5921df706d45e853537dea51508f" dependencies = [ "clap_builder", "clap_derive", ] [[package]] name = "clap_builder" version = "4.5.49" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0025e98baa12e766c67ba13ff4695a887a1eba19569aad00a472546795bd6730" dependencies = [ "anstream", "anstyle", "clap_lex", "strsim", ] [[package]] name = "clap_derive" version = "4.5.49" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671" dependencies = [ "heck", "proc-macro2", "quote", "syn", ] [[package]] name = "clap_lex" version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" [[package]] name = "colorchoice" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" [[package]] name = "core-foundation" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" dependencies = [ "core-foundation-sys", "libc", ] [[package]] name = "core-foundation" version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" dependencies = [ "core-foundation-sys", "libc", ] [[package]] name = "core-foundation-sys" version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "diff" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" [[package]] name = "errno" version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", "windows-sys 0.61.2", ] [[package]] name = "fastrand" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "find-msvc-tools" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127" [[package]] name = "foreign-types" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" dependencies = [ "foreign-types-shared", ] [[package]] name = "foreign-types-shared" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "getopts" version = "0.2.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfe4fbac503b8d1f88e6676011885f34b7174f46e59956bba534ba83abded4df" dependencies = [ "unicode-width", ] [[package]] name = "getrandom" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" dependencies = [ "cfg-if", "libc", "r-efi", "wasip2", ] [[package]] name = "heck" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hwlib" version = "0.10.0" dependencies = [ "anyhow", "clap", "minreq", "os-release", "pretty_assertions", "pyo3", "serde", "serde_json", "simple_test_case", "smbios-lib", ] [[package]] name = "indoc" version = "2.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4c7245a08504955605670dbf141fceab975f15ca21570696aebe9d2e71576bd" [[package]] name = "io-kit-sys" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "617ee6cf8e3f66f3b4ea67a4058564628cde41901316e19f559e14c7c72c5e7b" dependencies = [ "core-foundation-sys", "mach2", ] [[package]] name = "is_terminal_polyfill" version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "itoa" version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" version = "0.2.177" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" [[package]] name = "linux-raw-sys" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" [[package]] name = "log" version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" [[package]] name = "mach2" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d640282b302c0bb0a2a8e0233ead9035e3bed871f0b7e81fe4a1ec829765db44" dependencies = [ "libc", ] [[package]] name = "memchr" version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" [[package]] name = "memoffset" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" dependencies = [ "autocfg", ] [[package]] name = "minreq" version = "2.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05015102dad0f7d61691ca347e9d9d9006685a64aefb3d79eecf62665de2153d" dependencies = [ "native-tls", "serde", "serde_json", ] [[package]] name = "native-tls" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e" dependencies = [ "libc", "log", "openssl", "openssl-probe", "openssl-sys", "schannel", "security-framework", "security-framework-sys", "tempfile", ] [[package]] name = "once_cell" version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "once_cell_polyfill" version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" [[package]] name = "openssl" version = "0.10.74" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24ad14dd45412269e1a30f52ad8f0664f0f4f4a89ee8fe28c3b3527021ebb654" dependencies = [ "bitflags", "cfg-if", "foreign-types", "libc", "once_cell", "openssl-macros", "openssl-sys", ] [[package]] name = "openssl-macros" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "openssl-probe" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" [[package]] name = "openssl-sys" version = "0.9.110" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a9f0075ba3c21b09f8e8b2026584b1d18d49388648f2fbbf3c97ea8deced8e2" dependencies = [ "cc", "libc", "pkg-config", "vcpkg", ] [[package]] name = "os-release" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "82f29ae2f71b53ec19cc23385f8e4f3d90975195aa3d09171ba3bef7159bec27" dependencies = [ "lazy_static", ] [[package]] name = "pkg-config" version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" [[package]] name = "portable-atomic" version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483" [[package]] name = "pretty_assertions" version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d" dependencies = [ "diff", "yansi", ] [[package]] name = "proc-macro2" version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" dependencies = [ "unicode-ident", ] [[package]] name = "pyo3" version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ba0117f4212101ee6544044dae45abe1083d30ce7b29c4b5cbdfa2354e07383" dependencies = [ "indoc", "libc", "memoffset", "once_cell", "portable-atomic", "pyo3-build-config", "pyo3-ffi", "pyo3-macros", "unindent", ] [[package]] name = "pyo3-build-config" version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fc6ddaf24947d12a9aa31ac65431fb1b851b8f4365426e182901eabfb87df5f" dependencies = [ "target-lexicon", ] [[package]] name = "pyo3-ffi" version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "025474d3928738efb38ac36d4744a74a400c901c7596199e20e45d98eb194105" dependencies = [ "libc", "pyo3-build-config", ] [[package]] name = "pyo3-macros" version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e64eb489f22fe1c95911b77c44cc41e7c19f3082fc81cce90f657cdc42ffded" dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", "syn", ] [[package]] name = "pyo3-macros-backend" version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "100246c0ecf400b475341b8455a9213344569af29a3c841d29270e53102e0fcf" dependencies = [ "heck", "proc-macro2", "pyo3-build-config", "quote", "syn", ] [[package]] name = "quote" version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" dependencies = [ "proc-macro2", ] [[package]] name = "r-efi" version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" [[package]] name = "rustix" version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" dependencies = [ "bitflags", "errno", "libc", "linux-raw-sys", "windows-sys 0.61.2", ] [[package]] name = "ryu" version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" [[package]] name = "schannel" version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "891d81b926048e76efe18581bf793546b4c0eaf8448d72be8de2bbee5fd166e1" dependencies = [ "windows-sys 0.61.2", ] [[package]] name = "security-framework" version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ "bitflags", "core-foundation 0.9.4", "core-foundation-sys", "libc", "security-framework-sys", ] [[package]] name = "security-framework-sys" version = "2.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc1f0cbffaac4852523ce30d8bd3c5cdc873501d96ff467ca09b6767bb8cd5c0" dependencies = [ "core-foundation-sys", "libc", ] [[package]] name = "serde" version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" dependencies = [ "serde_core", "serde_derive", ] [[package]] name = "serde_core" version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "serde_json" version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" dependencies = [ "itoa", "memchr", "ryu", "serde", "serde_core", ] [[package]] name = "shlex" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "simple_test_case" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6909e2382b73068b0172c9c28726b6fb9efeef51742ecfd05b9260c62c42bb8e" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "smbios-lib" version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48c18320ad3d997a100cb948fc020111936c530eddfde947f467083730e39e72" dependencies = [ "core-foundation 0.10.1", "core-foundation-sys", "getopts", "io-kit-sys", "libc", "mach2", "serde", "serde_json", ] [[package]] name = "strsim" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "target-lexicon" version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df7f62577c25e07834649fc3b39fafdc597c0a3527dc1c60129201ccfcbaa50c" [[package]] name = "tempfile" version = "3.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16" dependencies = [ "fastrand", "getrandom", "once_cell", "rustix", "windows-sys 0.61.2", ] [[package]] name = "unicode-ident" version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" [[package]] name = "unicode-width" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" [[package]] name = "unindent" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3" [[package]] name = "utf8parse" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "vcpkg" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "wasip2" version = "1.0.1+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" dependencies = [ "wit-bindgen", ] [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" [[package]] name = "windows-sys" version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" dependencies = [ "windows-targets", ] [[package]] name = "windows-sys" version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" dependencies = [ "windows-link", ] [[package]] name = "windows-targets" version = "0.53.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" dependencies = [ "windows-link", "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_gnullvm", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" [[package]] name = "windows_aarch64_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" [[package]] name = "windows_i686_gnu" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" [[package]] name = "windows_i686_gnullvm" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" [[package]] name = "windows_i686_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" [[package]] name = "windows_x86_64_gnu" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" [[package]] name = "windows_x86_64_gnullvm" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" [[package]] name = "windows_x86_64_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" [[package]] name = "wit-bindgen" version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" [[package]] name = "yansi" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" hwlib-0.10.0/Cargo.toml0000644000000035430000000000100102220ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" name = "hwlib" version = "0.10.0" authors = [ "Canonical Hardware Certification ", "Nadzeya Hutsko ", "Matias Piipari ", ] build = "build.rs" autolib = false autobins = false autoexamples = false autotests = false autobenches = false description = "Tool for checking Ubuntu hardware certification status" homepage = "https://github.com/canonical/hardware-api/" documentation = "https://github.com/canonical/hardware-api/" readme = "README.md" license = "LGPL-3.0-only" repository = "https://github.com/canonical/hardware-api/" [lib] name = "hwlib" crate-type = [ "cdylib", "rlib", ] path = "src/lib.rs" [[bin]] name = "hwctl" path = "bin/hwctl.rs" [dependencies.anyhow] version = "~1.0.0" [dependencies.clap] version = "4.5.41" features = [ "derive", "env", ] [dependencies.minreq] version = "2.14.0" features = [ "native-tls", "json-using-serde", ] default-features = false [dependencies.os-release] version = "0.1.0" [dependencies.pyo3] version = "0.26.0" features = ["extension-module"] [dependencies.serde] version = "~1.0.0" features = ["derive"] [dependencies.serde_json] version = "~1.0.0" [dependencies.smbios-lib] version = "0.9.0" [dev-dependencies.pretty_assertions] version = "1.4.1" [dev-dependencies.simple_test_case] version = "1.2.0" hwlib-0.10.0/Cargo.toml.orig000064400000000000000000000021161046102023000136760ustar 00000000000000[package] name = "hwlib" description = "Tool for checking Ubuntu hardware certification status" version = "0.10.0" edition = "2021" authors = [ "Canonical Hardware Certification ", "Nadzeya Hutsko ", "Matias Piipari ", ] license = "LGPL-3.0-only" documentation = "https://github.com/canonical/hardware-api/" homepage = "https://github.com/canonical/hardware-api/" repository = "https://github.com/canonical/hardware-api/" [lib] name = "hwlib" crate-type = ["cdylib", "rlib"] [[bin]] name = "hwctl" path = "bin/hwctl.rs" [dependencies] anyhow = "~1.0.0" clap = { version = "4.5.41", features = ["derive", "env"] } minreq = { version = "2.14.0", features = ["native-tls", "json-using-serde"], default-features = false } os-release = { version = "0.1.0" } pyo3 = { version = "0.26.0", features = ["extension-module"] } serde = { version = "~1.0.0", features = ["derive"] } serde_json = "~1.0.0" smbios-lib = "0.9.0" [dev-dependencies] pretty_assertions = "1.4.1" simple_test_case = "1.2.0" hwlib-0.10.0/LICENSE000064400000000000000000000167441046102023000120300ustar 00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. hwlib-0.10.0/README.md000064400000000000000000000037161046102023000122750ustar 00000000000000# Hardware API Client [![Snapcraft][snapcraft-badge]][snapcraft-site] [![Test client lib and CLI tool][test-badge]][test-site] The **Hardware API Client** is the tool to check the certification status of hardware configurations. It consists of both the `hwlib` library and `hwctl` CLI tool. - `hwlib`: Rust library for communicating with [the API server](../server/). - `hwctl`: CLI tool leveraging the `hwlib` library. ## Basic Usage To check the machine certification status, simply run `hwctl` with root[^sudo] privileges: ```shell sudo hwctl ``` To send the request to a different server than the [default][hw-server], specify the `HW_API_URL` environment variable: ```shell sudo HW_API_URL=https://your.server.url hwctl ``` ## Installation `hwctl` is available on all major Linux distributions. On snap-ready systems, you can install it on the command-line with: ```shell sudo snap install hwctl ``` On Questing Quokka (25.10), you can also install it using `apt`: ```shell sudo apt-get install hwctl ``` ## Community and Support You can report any issues, bugs, or feature requests on the project's [GitHub repository][github-issues]. ## Contribute to the Hardware API Client The Hardware API Client is open source. Contributions are welcome. If you're interested, start with the [client contribution guide](./CONTRIBUTING.md). ## License and Copyright The Hardware API Client is released under the under the [LGPL-3.0 license](./LICENSE) © 2025 Canonical Ltd. [^sudo]: The client requires root access since we collect the hardware information using SMBIOS data. [snapcraft-badge]: https://snapcraft.io/hwctl/badge.svg [snapcraft-site]: https://snapcraft.io/hwctl [test-badge]: https://github.com/canonical/hardware-api/actions/workflows/test_client.yaml/badge.svg [test-site]: https://github.com/canonical/hardware-api/actions/workflows/test_client.yaml [hw-server]: https://hw.ubuntu.com [github-issues]: https://github.com/canonical/hardware-api/issues hwlib-0.10.0/bin/hwctl.rs000064400000000000000000000046631046102023000132570ustar 00000000000000/* Copyright 2024 Canonical Ltd. * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 3, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Written by: * Canonical Ltd * Nadzeya Hutsko */ use anyhow::{Context, Result}; use clap::Parser; use std::process::ExitCode; use hwlib::models::request_validators::{CertificationStatusRequest, Paths}; use hwlib::send_certification_status_request; /// CLI tool to check hardware certification status. /// /// The utility checks the Ubuntu Hardware Certification status of your /// system. It verifies whether your exact machine model or a similar system has been /// certified and displays which Ubuntu releases the certification covers for it. /// /// For more information about the Ubuntu Hardware Certification Program, visit /// the certification website: https://ubuntu.com/certified /// /// Note that root privileges are typically required to run this command. #[derive(Parser, Debug)] #[command(version, about, long_about, verbatim_doc_comment)] struct Args { #[arg( long = "server", env = "HW_API_URL", default_value = "https://hw.ubuntu.com", help = "API server URL" )] hw_api_url: String, } fn main() -> ExitCode { let args = Args::parse(); match run(args.hw_api_url) { Ok(_) => ExitCode::SUCCESS, Err(e) => { eprintln!("ERROR: {e:?}"); ExitCode::FAILURE } } } fn run(server_url: String) -> Result<()> { let cert_status_request = CertificationStatusRequest::new(Paths::default()).context("cannot collect system data")?; let response = send_certification_status_request(server_url, &cert_status_request) .context("cannot send certification status request")?; let response_json = serde_json::to_string_pretty(&response).context("cannot serialize response as JSON")?; println!("{response_json}"); Ok(()) } hwlib-0.10.0/build.rs000064400000000000000000000003211046102023000124500ustar 00000000000000fn main() { let os_release_file_path = std::env::var("OS_RELEASE_FILE_PATH").unwrap_or("/etc/os-release".to_owned()); println!("cargo:rustc-env=OS_RELEASE_FILE_PATH={os_release_file_path}"); } hwlib-0.10.0/hwctl.1000064400000000000000000000027231046102023000122160ustar 00000000000000.Dd December 5, 2024 .Dt HWCTL 1 .Os Ubuntu .Sh NAME .Nm hwctl .Nd CLI tool to check hardware certification status .Sh SYNOPSIS .Nm .Pp .Nm .Op Fl h | \-help .Op Fl V | \-version .Op Fl \-server Ar URL .Sh DESCRIPTION The .Nm utility checks the .Em Ubuntu Hardware Certification status of your system. .Pp .Nm verifies whether your exact machine model or a similar system has been certified and displays which Ubuntu releases the certification covers for it. For more information about the .Em Ubuntu Hardware Certification Program , visit .Lk https://ubuntu.com/certified "the certification website" . .Pp Note that root privileges are typically required to run this command. .Sh OPTIONS .Bl -tag -width ".Fl \-server" .It Fl h , \-help Print help information and exit. .It Fl V , \-version Print version information and exit. .It Fl \-server Ar URL Specify the API server URL. This overrides the default value and the .Ev HW_API_URL environment variable. .El .Sh ENVIRONMENT .Bl -tag -width "HW_API_URL" -compact .It Ev HW_API_URL Specifies the hardware-api server URL that .Nm uses for certification queries. The default value is .Lk https://hw.ubuntu.com . .El .Sh SEE ALSO .Xr dmidecode 8 , .Xr lshw 1 .Sh AUTHORS Written by .An Nadzeya Hutsko Aq Mt nadzeya.hutsko@canonical.com . .Sh BUGS Only amd64 architecture is currently supported. .Pp For information about open bugs, visit .Lk https://github.com/canonical/hardware-api/issues/ . .Sh COPYRIGHT Copyright \(co 2024 Canonical Ltd. hwlib-0.10.0/pytests/test_cert_status.py000064400000000000000000000016401046102023000164740ustar 00000000000000# Copyright 2024 Canonical Ltd. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License version # 3, as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # Written by: # Nadzeya Hutsko def test_send_certification_request(): """Verify that we can import and call the library in the python code""" import hwlib assert hasattr(hwlib, "send_certification_request") assert callable(hwlib.send_certification_request) hwlib-0.10.0/snapcraft.yaml000064400000000000000000000033751046102023000136640ustar 00000000000000name: hwctl adopt-info: hwctl license: GPL-3.0-only summary: Canonical Certified Hardware API Client description: | `hwctl` is a `hwlib` backed CLI tool for collecting and sending hardware information to a Hardware API server to find certification status of device models. The production deployment of the Hardware API server is available at https://hw.ubuntu.com. You can view the Hardware API OpenAPI schema at https://canonical.github.io/hardware-api/. website: - https://github.com/canonical/hardware-api - https://canonical.github.io/hardware-api - https://hw.ubuntu.com source-code: https://github.com/canonical/hardware-api/tree/main/client issues: https://github.com/canonical/hardware-api/issues contact: https://github.com/canonical/hardware-api/issues base: core22 grade: stable confinement: strict architectures: - build-on: [amd64] apps: hwctl: command: bin/hwctl plugs: - hardware-observe - kernel-module-observe - network - network-setup-observe - system-observe parts: hwctl: plugin: rust source: . build-packages: - jq - libssl-dev - pkg-config stage-packages: - kmod override-pull: | craftctl default metadata="$(cargo metadata --no-deps --format-version 1)" version="$(echo "$metadata" | jq -r .packages[0].version)" craftctl set version="$version" build-environment: - OS_RELEASE_FILE_PATH: /var/lib/snapd/hostfs/etc/os-release override-build: | craftctl default cp hwctl.1 $CRAFT_PART_INSTALL/hwctl.1 organize: # Snap does not support manpages. In order to enable them, execute: # sudo ln -s /snap/hwctl/current/man/man1/hwctl.1 /usr/share/man/man1/hwctl.1 hwctl.1: man/man1/hwctl.1 hwlib-0.10.0/src/collectors/cpuinfo.rs000064400000000000000000000142331046102023000157630ustar 00000000000000/* Copyright 2024 Canonical Ltd. * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 3, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Written by: * Nadzeya Hutsko */ use anyhow::{Context, Result}; use std::{collections::HashMap, fs::read_to_string, io::ErrorKind::NotFound, path::Path}; #[derive(Debug)] pub struct CpuInfo { pub platform: String, pub cores_count: usize, pub cpu_type: String, pub model: String, pub model_number: String, pub model_version: String, pub model_revision: String, pub cache: Option, pub bogomips: Option, pub speed: u64, } impl CpuInfo { /// Parse cpuinfo file the same way it's done in checkbox: /// pub fn from_file(cpuinfo_filepath: &Path) -> Result { let mut attributes: HashMap<&str, &str> = HashMap::new(); let mut cores_count = 0; let raw_cpuinfo = read_to_string(cpuinfo_filepath).with_context(|| { format!("cannot read CPU info file {:?}", cpuinfo_filepath.display()) })?; for line in raw_cpuinfo.lines() { let trimmed_line = line.trim(); if trimmed_line.is_empty() { continue; } if let Some((key, value)) = trimmed_line.split_once(':') { let key = key.trim_end(); if key == "processor" { cores_count += 1; } attributes.insert(key, value.trim_start()); } } let arch = std::env::consts::ARCH; let speed_str = attributes.get("cpu MHz").copied(); let speed = speed_str .map(CpuSpeed::try_from) .transpose()? .unwrap_or_default() .get_m_hz_as_int(); let platform = arch.to_string(); let model = attributes .get("Model") .or_else(|| attributes.get("model name")) .unwrap_or(&arch) .to_string(); let cpu_type = attributes.get("vendor_id").unwrap_or(&arch).to_string(); let model_number = attributes .remove("cpu family") .unwrap_or_default() .to_string(); let model_version = attributes.remove("model").unwrap_or_default().to_string(); let model_revision = attributes .remove("stepping") .unwrap_or_default() .to_string(); let cache = attributes .remove("cache size") .map(parse_cache_size) .transpose()?; let bogomips = attributes .remove("bogomips") .map(parse_bogomips) .transpose()?; Ok(CpuInfo { platform, cores_count, cpu_type, model, model_number, model_version, model_revision, cache, bogomips, speed, }) } } #[derive(Debug, Default)] pub struct CpuFrequency { m_hz: u64, } impl CpuFrequency { /// Read max CPU frequency from file and parse it in MHz as it's done in checkbox. /// pub fn from_k_hz_file(max_cpu_frequency_filepath: &Path) -> Result { match read_to_string(max_cpu_frequency_filepath) { Ok(raw_freq) => { let k_hz: u64 = raw_freq.trim().parse()?; Ok(Self::from_k_hz(k_hz)) } Err(e) if e.kind() == NotFound => Ok(Self::from_m_hz(0)), Err(e) => Err(e).with_context(|| { format!( "cannot read CPU frequency file: {:?}", max_cpu_frequency_filepath.display() ) }), } } /// Create a CpuFrequency from a frequency in kHz pub const fn from_k_hz(k_hz: u64) -> Self { Self { m_hz: k_hz / 1000 } // Convert kHz to MHz } /// Create a CpuFrequency from a frequency in MHz pub const fn from_m_hz(m_hz: u64) -> Self { Self { m_hz } } pub const fn get_m_hz(&self) -> u64 { self.m_hz } } #[derive(Debug, Default)] struct CpuSpeed { m_hz: f64, } impl CpuSpeed { /// Get the frequency in MHz as a rounded integer fn get_m_hz_as_int(&self) -> u64 { self.m_hz.round() as u64 } } impl TryFrom<&str> for CpuSpeed { type Error = anyhow::Error; fn try_from(raw: &str) -> Result { Ok(CpuSpeed { m_hz: raw.parse::()?, }) } } fn parse_cache_size(cache_size: &str) -> Result { Ok(cache_size .strip_suffix(" KB") .unwrap_or(cache_size) .parse::()?) } fn parse_bogomips(bogomips: &str) -> Result { let bogo_str = bogomips.replace(' ', ""); Ok(bogo_str.parse::().map(|b| b.round() as u64)?) } #[cfg(test)] mod tests { use super::{CpuFrequency, CpuInfo}; use crate::helpers::test_utils::get_test_filepath; #[test] fn test_parsing_cpuinfo() { let cpuinfo = CpuInfo::from_file(&get_test_filepath("arm64/rpi4b8g/cpuinfo")).unwrap(); assert_eq!(cpuinfo.platform, std::env::consts::ARCH); assert_eq!(cpuinfo.cores_count, 4); assert_eq!(cpuinfo.cpu_type, std::env::consts::ARCH); assert_eq!(cpuinfo.model, "Raspberry Pi 4 Model B Rev 1.4"); } #[test] fn test_read_max_cpu_frequency() { let cpu_freq = CpuFrequency::from_k_hz_file(&get_test_filepath("arm64/rpi4b8g/cpuinfo_max_freq")) .unwrap(); assert_eq!(cpu_freq.m_hz, 600); } } hwlib-0.10.0/src/collectors/hardware_info.rs000064400000000000000000000302411046102023000171250ustar 00000000000000/* Copyright 2024 Canonical Ltd. * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 3, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Written by: * Nadzeya Hutsko */ use anyhow::{anyhow, Context, Result}; use smbioslib::{ SMBiosBaseboardInformation, SMBiosData, SMBiosEntryPoint32, SMBiosEntryPoint64, SMBiosInformation, SMBiosProcessorInformation, SMBiosSystemChassisInformation, SMBiosSystemInformation, SMBiosVersion, }; use std::{ fs::read_to_string, io::{Error as IoError, ErrorKind}, path::Path, }; use crate::{ collectors::cpuinfo::{CpuFrequency, CpuInfo}, helpers::append_to_pathbuf, models::devices::{Bios, Board, Chassis, Processor}, }; impl TryFrom<&SMBiosInformation<'_>> for Bios { type Error = anyhow::Error; fn try_from(bios_info: &SMBiosInformation) -> Result { let release_date = bios_info.release_date().to_string(); let firmware_revision = match ( bios_info.system_bios_major_release(), bios_info.system_bios_minor_release(), ) { (Some(major), Some(minor)) => Some(format!("{major}.{minor}")), _ => None, }; Ok(Self { firmware_revision, release_date: Some(release_date), revision: Some(bios_info.version().to_string()), vendor: bios_info.vendor().to_string(), version: bios_info.version().to_string(), }) } } /// Retrieve CPU information from SMBIOS impl TryFrom<(&SMBiosProcessorInformation<'_>, &Path)> for Processor { type Error = anyhow::Error; fn try_from(value: (&SMBiosProcessorInformation, &Path)) -> Result { let (processor_info, max_cpu_frequency_filepath) = value; let cpu_identifier = processor_info .processor_id() .ok_or_else(|| anyhow!("processor ID cannot be retrieved"))?; let cpu_freq = CpuFrequency::from_k_hz_file(max_cpu_frequency_filepath)?.get_m_hz(); Ok(Processor { identifier: Some(*cpu_identifier), frequency: cpu_freq, manufacturer: processor_info.processor_manufacturer().to_string(), version: processor_info.processor_version().to_string(), }) } } /// Retrieve CPU information from cpuinfo file impl TryFrom<(&Path, &Path)> for Processor { type Error = anyhow::Error; fn try_from(value: (&Path, &Path)) -> Result { let (cpuinfo_filepath, max_cpu_frequency_filepath) = value; let cpu_info = CpuInfo::from_file(cpuinfo_filepath)?; let cpu_freq = CpuFrequency::from_k_hz_file(max_cpu_frequency_filepath)?.get_m_hz(); Ok(Processor { identifier: None, frequency: cpu_freq, manufacturer: cpu_info.cpu_type, version: cpu_info.model, }) } } impl TryFrom<&SMBiosSystemChassisInformation<'_>> for Chassis { type Error = anyhow::Error; fn try_from(chassis_info: &SMBiosSystemChassisInformation) -> Result { let chassis_type = chassis_info .chassis_type() .ok_or("failed to get chassis type") .unwrap() .to_string(); let manufacturer = chassis_info.manufacturer().ok().unwrap_or_default(); let sku = chassis_info.sku_number().ok().unwrap_or_default(); let version = chassis_info.version().ok().unwrap_or_default(); Ok(Chassis { chassis_type, manufacturer, sku, version, }) } } impl TryFrom<&SMBiosBaseboardInformation<'_>> for Board { type Error = anyhow::Error; fn try_from(board_info: &SMBiosBaseboardInformation) -> Result { let manufacturer = board_info.manufacturer().ok().unwrap_or_default(); let product_name = board_info.product().ok().unwrap_or_default(); let version = board_info.version().ok().unwrap_or_default(); Ok(Board { manufacturer, product_name, version, }) } } impl TryFrom<&Path> for Board { type Error = anyhow::Error; fn try_from(device_tree_filepath: &Path) -> Result { let try_read = |file| { read_to_string(file) .as_ref() .map(|s| s.trim()) .unwrap_or("Unknown") .to_string() }; // Since it's still not clear how to fetch the manufacturer in such case, // we set the 'Unknown' value to it. let manufacturer = String::from("Unknown"); let product_name = try_read(append_to_pathbuf( device_tree_filepath.to_path_buf(), "model", )); let version = try_read(append_to_pathbuf( device_tree_filepath.to_path_buf(), "compatible", )); Ok(Board { manufacturer, product_name, version, }) } } pub struct SystemInfo { pub product_name: String, pub manufacturer: String, } impl SystemInfo { pub fn try_from_smbios(system_data: &SMBiosSystemInformation) -> Result { Ok(SystemInfo { product_name: system_data.product_name().ok().unwrap_or_default(), manufacturer: system_data.manufacturer().ok().unwrap_or_default(), }) } } #[cfg(target_os = "linux")] /// Overwrite smbioslib::table_load_from_device to use parameters for files /// so we can test our code without reading smbios data from the machine that /// runs the test. pub(crate) fn table_load_from_device( entry_file: &Path, table_file: &Path, ) -> Result { let version = SMBiosEntryPoint64::try_load_from_file(entry_file) .with_context(|| format!("cannot load SMBIOS entry from: {:?}", entry_file.display())) .map(|entry_point| SMBiosVersion { major: entry_point.major_version(), minor: entry_point.minor_version(), revision: 0, }) .or_else(|err| { if let Some(io_err) = err.downcast_ref::() { if io_err.kind() != ErrorKind::InvalidData { return Err(err); } SMBiosEntryPoint32::try_load_from_file(entry_file) .with_context(|| { format!("cannot load SMBIOS entry from: {:?}", entry_file.display()) }) .map(|entry_point| SMBiosVersion { major: entry_point.major_version(), minor: entry_point.minor_version(), revision: 0, }) } else { Err(err) } })?; SMBiosData::try_load_from_file(table_file.to_str().unwrap(), Some(version)) .with_context(|| format!("cannot load SMBIOS table from: {:?}", table_file.display())) } #[cfg(test)] mod tests { use super::*; use crate::helpers::test_utils::get_test_filepath; #[test] fn test_table_load_from_device() { let result = table_load_from_device( &get_test_filepath("amd64/dgx_station/smbios_entry_point"), &get_test_filepath("amd64/dgx_station/DMI"), ); assert!(result.is_ok()); } #[test] fn test_bios_from_smbios() { let smbios_data = table_load_from_device( &get_test_filepath("amd64/dgx_station/smbios_entry_point"), &get_test_filepath("amd64/dgx_station/DMI"), ) .unwrap(); let bios_info_vec = smbios_data.collect::(); let bios_info = bios_info_vec.first().unwrap(); let bios = Bios::try_from(bios_info).unwrap(); assert!(bios.firmware_revision.is_some()); assert!(bios.release_date.is_some()); assert!(bios.revision.is_some()); assert_eq!(bios.vendor, "American Megatrends Inc."); assert_eq!(bios.version, "0406"); assert_eq!(bios.release_date.unwrap(), "08/27/2018"); assert_eq!(bios.firmware_revision.unwrap(), "5.11"); assert_eq!(bios.revision.unwrap(), "0406"); } #[test] fn test_bios_release_date_smbios() { let smbios_data = table_load_from_device( &get_test_filepath("amd64/questing_vm/smbios_entry_point"), &get_test_filepath("amd64/questing_vm/DMI"), ) .unwrap(); let bios_info_vec = smbios_data.collect::(); let bios_info = bios_info_vec.first().unwrap(); let bios = Bios::try_from(bios_info).unwrap(); assert_eq!(bios.release_date.unwrap(), "2/2/98"); } #[test] fn test_processor_from_smbios() { let smbios_data = table_load_from_device( &get_test_filepath("amd64/dgx_station/smbios_entry_point"), &get_test_filepath("amd64/dgx_station/DMI"), ) .unwrap(); let processor_info_vec = smbios_data.collect::(); let processor_info = processor_info_vec.first().unwrap(); let processor = Processor::try_from(( processor_info, get_test_filepath("amd64/dgx_station/cpuinfo_max_freq").as_path(), )) .unwrap(); assert_eq!( processor.identifier, Some([0xf1, 0x6, 0x4, 0x0, 0xff, 0xfb, 0xeb, 0xbf]) // Broadwell ID ); assert_eq!(processor.frequency, 800); assert_eq!(processor.manufacturer, "Intel"); assert_eq!( processor.version, "Intel(R) Xeon(R) CPU E5-2698 v4 @ 2.20GHz" ); } #[test] fn test_collect_chassis_info() { let smbios_data = table_load_from_device( &get_test_filepath("amd64/dgx_station/smbios_entry_point"), &get_test_filepath("amd64/dgx_station/DMI"), ) .unwrap(); let chassis_info_vec = smbios_data.collect::(); let chassis_info = chassis_info_vec.first().unwrap(); let chassis = Chassis::try_from(chassis_info).unwrap(); assert_eq!(chassis.chassis_type, "Desktop"); assert_eq!(chassis.manufacturer, "EMPTY"); assert_eq!(chassis.sku, "Default string"); assert_eq!(chassis.version, "Default string"); } #[test] fn test_collect_motherboard_info() { let smbios_data = table_load_from_device( &get_test_filepath("amd64/dgx_station/smbios_entry_point"), &get_test_filepath("amd64/dgx_station/DMI"), ) .unwrap(); let board_info_vec = smbios_data.collect::(); let board_info = board_info_vec.first().unwrap(); let board = Board::try_from(board_info).unwrap(); assert_eq!(board.manufacturer, "EMPTY"); assert_eq!(board.product_name, "X99-E-10G WS"); assert_eq!(board.version, "Rev 1.xx"); } #[test] fn test_collect_motherboard_info_from_device_tree() { let board = Board::try_from(get_test_filepath("arm64/rpi4b8g/device-tree/").as_path()).unwrap(); assert_eq!(board.manufacturer, "Unknown"); assert_eq!(board.product_name, "Raspberry Pi 4 Model B Rev 1.5"); assert_eq!(board.version, "raspberrypi,4-model-bbrcm,bcm2711"); } #[test] fn test_get_system_info() { let smbios_data = table_load_from_device( &get_test_filepath("amd64/dgx_station/smbios_entry_point"), &get_test_filepath("amd64/dgx_station/DMI"), ) .unwrap(); let system_data_vec = smbios_data.collect::(); let system_data = system_data_vec.first().unwrap(); let system_info = SystemInfo::try_from_smbios(system_data).unwrap(); assert_eq!(system_info.product_name, "DGX Station"); assert_eq!(system_info.manufacturer, "NVIDIA"); } } hwlib-0.10.0/src/collectors/mod.rs000064400000000000000000000014071046102023000150760ustar 00000000000000/* Copyright 2024 Canonical Ltd. * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 3, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Written by: * Nadzeya Hutsko */ pub mod cpuinfo; pub mod hardware_info; pub mod os_info; hwlib-0.10.0/src/collectors/os_info.rs000064400000000000000000000116561046102023000157620ustar 00000000000000/* Copyright 2024 Canonical Ltd. * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 3, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Written by: * Nadzeya Hutsko */ use anyhow::{anyhow, Context, Result}; use os_release::OsRelease; use std::{fs::read_to_string, path::Path, process::Command}; use crate::{ constants::LSMOD, models::software::{KernelPackage, OS}, }; pub(crate) trait CommandRunner { fn run_command(&self, cmd: &str, args: &[&str]) -> Result; } pub(crate) struct SystemCommandRunner; impl CommandRunner for SystemCommandRunner { fn run_command(&self, cmd: &str, args: &[&str]) -> Result { let output = Command::new(cmd).args(args).output()?; let stdout = String::from_utf8(output.stdout)?; Ok(stdout) } } impl OS { pub(crate) fn try_new( os_release_filepath: &Path, proc_version_filepath: &Path, runner: &impl CommandRunner, ) -> Result { let release = OsRelease::new_from(os_release_filepath).with_context(|| { format!("cannot read OS release information from: {os_release_filepath:?}",) })?; let OsRelease { version_codename: codename, name: distributor, version_id: version, .. } = release; let kernel = KernelPackage::try_new(proc_version_filepath, runner)?; Ok(OS { codename, distributor, version, kernel, }) } } impl KernelPackage { pub(crate) fn try_new( proc_version_filepath: &Path, runner: &impl CommandRunner, ) -> Result { let kernel_version = read_to_string(proc_version_filepath).with_context(|| { format!( "cannot read kernel version from: {:?}", proc_version_filepath.display() ) })?; let kernel_version = kernel_version .split_whitespace() .nth(2) .unwrap_or_default() .to_string(); let loaded_modules_str = runner .run_command(LSMOD, &[]) .with_context(|| "cannot get loaded kernel modules using lsmod")?; let loaded_modules: Vec = loaded_modules_str .lines() .skip(1) // skip the header .map(|line| line.split_whitespace().next().unwrap_or("").to_string()) .collect(); Ok(KernelPackage { name: Some("Linux".to_string()), version: kernel_version, signature: None, // Signature is not available easily, so we set it to None for now. loaded_modules, }) } } pub(crate) fn to_debian_architecture(arch: &str) -> Result<&str> { let deb_arch = match arch.trim() { "aarch64" => "arm64", "arm" => "armhf", "loongarch64" => "loong64", "m68k" => "m68k", "mips" => "mips", "mips32r6" => "mipsr6", "mips64" => "mips64", "mips64r6" => "mips64r6", "powerpc" => "powerpc", "powerpc64" => "ppc64el", "riscv64" => "riscv64", "s390x" => "s390x", "sparc" => "sparc", "sparc64" => "sparc64", "x86" => "i386", "x86_64" => "amd64", _ => return Err(anyhow!("cannot convert {arch:?} to debian architecture")), }; Ok(deb_arch) } #[cfg(test)] mod tests { use super::*; use crate::helpers::test_utils::{get_test_filepath, MockCommandRunner}; #[test] fn test_to_debian_architecture() { let result = to_debian_architecture("x86_64"); assert!(result.is_ok()); assert_eq!(result.unwrap(), "amd64"); let result = to_debian_architecture("fake_arch"); assert!(result.is_err()) } #[test] fn test_os_try_new() { let mock_calls = vec![((LSMOD, Vec::new()), Ok("Module Size Used\nsnd 61440 1\n"))]; let mock_runner = MockCommandRunner::new(mock_calls); let result = OS::try_new( get_test_filepath("arm64/rpi4b8g/os-release").as_path(), get_test_filepath("arm64/rpi4b8g/version").as_path(), &mock_runner, ); let os = result.unwrap(); assert_eq!(os.codename, "focal"); assert_eq!(os.distributor, "Ubuntu"); assert_eq!(os.version, "20.04"); assert_eq!(os.kernel.version, "5.4.0-1119-raspi"); assert_eq!(os.kernel.loaded_modules, vec!["snd".to_string()]); } } hwlib-0.10.0/src/constants.rs000064400000000000000000000023341046102023000141620ustar 00000000000000/* Copyright 2024 Canonical Ltd. * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 3, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Written by: * Nadzeya Hutsko */ pub const CERT_STATUS_ENDPOINT: &str = "/v1/certification/status"; pub const CPU_MAX_FREQ_FILE_PATH: &str = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"; pub const PROC_CPUINFO_FILE_PATH: &str = "/proc/cpuinfo"; pub const PROC_DEVICE_TREE_DIR_PATH: &str = "/proc/device-tree/"; pub const PROC_VERSION_FILE_PATH: &str = "/proc/version"; // The os-release file path is defined in build.rs at build time pub const OS_RELEASE_FILE_PATH: &str = env!("OS_RELEASE_FILE_PATH"); pub const LSMOD: &str = "/usr/bin/lsmod"; hwlib-0.10.0/src/helpers.rs000064400000000000000000000066011046102023000136110ustar 00000000000000/* Copyright 2024 Canonical Ltd. * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 3, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Written by: * Nadzeya Hutsko */ use std::path::PathBuf; pub(crate) fn append_to_pathbuf(p: PathBuf, s: &str) -> PathBuf { let mut p = p.into_os_string(); p.push(s); p.into() } #[cfg(test)] pub(crate) mod test_utils { use crate::collectors::os_info::CommandRunner; use anyhow::{anyhow, bail, Result}; use std::{collections::HashMap, env, fs::read_dir, path::PathBuf}; type SystemCommand<'args> = (&'args str, Vec<&'args str>); pub(crate) struct MockCommandRunner<'args> { calls: HashMap, Result<&'args str>>, } impl<'args> MockCommandRunner<'args> { pub(crate) fn new(calls: Vec<(SystemCommand<'args>, Result<&'args str>)>) -> Self { let calls = calls.into_iter().collect(); Self { calls } } } impl CommandRunner for MockCommandRunner<'_> { fn run_command(&self, cmd: &str, args: &[&str]) -> Result { match self.calls.get(&(cmd, args.to_vec())) { Some(res) => match res { Ok(output) => Ok(output.to_string()), Err(e) => Err(anyhow!(e.to_string())), }, None => Err(anyhow!(format!("missing mock: cmd={cmd:?} args={args:?}"))), } } } pub(crate) fn get_test_filepath(file_name: &str) -> PathBuf { let mut path = get_project_root().unwrap(); let test_data_path = path.join("test_data"); if !test_data_path.is_dir() { // If test_data/ is not found, we're in the client root path.extend(["hwlib"]); } path.extend(["test_data", file_name]); path } fn get_project_root() -> Result { let path = env::current_dir()?; let path_ancestors = path.as_path().ancestors(); for p in path_ancestors { let has_cargo_lock = read_dir(p)? .flat_map(|entry| entry.ok()) .any(|entry| entry.file_name() == "Cargo.lock"); if has_cargo_lock { return Ok(PathBuf::from(p)); } } bail!("ran out of places to find Cargo.lock") } /// Reads data from the specified JSON file and substitutes /// placeholders with actual values provided in /// `vars`. Placeholders in the JSON file should follow the shell /// vars style format, like `${FOO}`. /// `vars is A list of key-value pairs, where each key corresponds /// to a placeholder name, and each value is the replacement /// string. pub(crate) fn apply_vars(mut content: String, vars: &[(&str, &str)]) -> String { for (k, v) in vars { content = content.replace(&format!("${k}"), v); } content } } hwlib-0.10.0/src/lib.rs000064400000000000000000000026611046102023000127170ustar 00000000000000/* Copyright 2024 Canonical Ltd. * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 3, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Written by: * Canonical Ltd * Nadzeya Hutsko */ #[cfg(test)] #[macro_use] extern crate pretty_assertions; pub mod collectors; mod constants; mod helpers; pub mod models; pub mod py_bindings; use anyhow::Result; use constants::CERT_STATUS_ENDPOINT; use models::{ request_validators::CertificationStatusRequest, response_validators::CertificationStatusResponse, }; pub fn send_certification_status_request( url: String, request: &CertificationStatusRequest, ) -> Result { let mut server_url = url.clone(); server_url.push_str(CERT_STATUS_ENDPOINT); let response = minreq::post(&server_url) .with_json(request)? .send()? .json()?; Ok(response) } hwlib-0.10.0/src/models/devices.rs000064400000000000000000000057371046102023000150650ustar 00000000000000/* Copyright 2024 Canonical Ltd. * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 3, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Written by: * Nadzeya Hutsko */ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct Audio { pub identifier: String, pub model: String, pub vendor: String, } #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct Bios { pub firmware_revision: Option, pub release_date: Option, pub revision: Option, pub vendor: String, pub version: String, } #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Default)] pub struct Board { pub manufacturer: String, pub product_name: String, pub version: String, } #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct Chassis { pub chassis_type: String, pub manufacturer: String, pub sku: String, pub version: String, } #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct GPU { pub codename: Option, pub identifier: String, pub manufacturer: String, pub status: Option, pub version: String, } #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct NetworkAdapter { pub bus: String, pub capacity: i32, pub identifier: String, pub model: String, pub vendor: String, } #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct PCIPeripheral { pub pci_id: String, pub name: String, pub status: Option, pub vendor: String, } #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct Processor { pub identifier: Option<[u8; 8]>, pub frequency: u64, pub manufacturer: String, pub version: String, } #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct USBPeripheral { pub usb_id: String, pub name: String, pub status: Option, pub vendor: String, } #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct VideoCapture { pub identifier: String, pub model: String, pub status: Option, pub vendor: String, } #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct WirelessAdapter { pub identifier: String, pub model: String, pub status: Option, pub vendor: String, } #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub enum DeviceStatus { Working, Breaking, } hwlib-0.10.0/src/models/mod.rs000064400000000000000000000014521046102023000142100ustar 00000000000000/* Copyright 2024 Canonical Ltd. * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 3, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Written by: * Nadzeya Hutsko */ pub mod devices; pub mod request_validators; pub mod response_validators; pub mod software; hwlib-0.10.0/src/models/request_validators.rs000064400000000000000000000245571046102023000173640ustar 00000000000000/* Copyright 2024 Canonical Ltd. * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 3, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Written by: * Nadzeya Hutsko */ use anyhow::{anyhow, Context, Result}; use serde::{Deserialize, Serialize}; use std::env::consts::ARCH; use std::path::PathBuf; use crate::{ collectors::{ hardware_info::{table_load_from_device, SystemInfo}, os_info::{to_debian_architecture, CommandRunner, SystemCommandRunner}, }, constants, models::{ devices::{Bios, Board, Chassis, PCIPeripheral, Processor, USBPeripheral}, software::OS, }, }; #[cfg(target_arch = "x86_64")] use smbioslib::{ SMBiosBaseboardInformation, SMBiosInformation, SMBiosProcessorInformation, SMBiosSystemChassisInformation, SMBiosSystemInformation, }; #[cfg(not(target_arch = "x86_64"))] use crate::collectors::cpuinfo::CpuInfo; #[derive(Debug, Clone)] pub struct Paths { pub smbios_entry_filepath: PathBuf, pub smbios_table_filepath: PathBuf, pub cpuinfo_filepath: PathBuf, pub max_cpu_frequency_filepath: PathBuf, pub device_tree_dirpath: PathBuf, pub os_release_filepath: PathBuf, pub proc_version_filepath: PathBuf, } impl Default for Paths { fn default() -> Self { let smbios_entry_filepath = PathBuf::from(smbioslib::SYS_ENTRY_FILE); let smbios_table_filepath = PathBuf::from(smbioslib::SYS_TABLE_FILE); let cpuinfo_filepath = PathBuf::from(constants::PROC_CPUINFO_FILE_PATH); let max_cpu_frequency_filepath = PathBuf::from(constants::CPU_MAX_FREQ_FILE_PATH); let device_tree_dirpath = PathBuf::from(constants::PROC_DEVICE_TREE_DIR_PATH); let os_release_filepath = PathBuf::from(constants::OS_RELEASE_FILE_PATH); let proc_version_filepath = PathBuf::from(constants::PROC_VERSION_FILE_PATH); Self { smbios_entry_filepath, smbios_table_filepath, cpuinfo_filepath, max_cpu_frequency_filepath, device_tree_dirpath, os_release_filepath, proc_version_filepath, } } } #[derive(Serialize, Deserialize, Debug)] pub struct CertificationStatusRequest { pub architecture: String, pub bios: Option, pub board: Board, pub chassis: Option, pub model: String, pub os: OS, pub pci_peripherals: Vec, pub processor: Processor, pub usb_peripherals: Vec, pub vendor: String, } impl CertificationStatusRequest { pub fn new(paths: Paths) -> Result { Self::new_with_runner(paths, &SystemCommandRunner) } pub(crate) fn new_with_runner(paths: Paths, runner: &impl CommandRunner) -> Result { Self::from(paths, runner) } #[cfg(target_arch = "x86_64")] fn from(paths: Paths, runner: &impl CommandRunner) -> Result { let Paths { smbios_entry_filepath, smbios_table_filepath, max_cpu_frequency_filepath, os_release_filepath, proc_version_filepath, .. } = paths; let data = table_load_from_device(&smbios_entry_filepath, &smbios_table_filepath)?; let bios_info_vec = data.collect::(); let bios_info = bios_info_vec .first() .ok_or_else(|| anyhow!("failed to load BIOS data"))?; let bios = Some(Bios::try_from(bios_info)?); let processor_info_vec = data.collect::(); let processor_info = processor_info_vec .first() .ok_or_else(|| anyhow!("failed to load processor data"))?; let processor = Processor::try_from((processor_info, max_cpu_frequency_filepath.as_path()))?; let chassis_info_vec = data.collect::(); let chassis = chassis_info_vec .first() .and_then(|info| Chassis::try_from(info).ok()); let board_info_vec = data.collect::(); let board = board_info_vec .first() .map(Board::try_from) .transpose()? .unwrap_or_else(Board::default); let system_data_vec = data.collect::(); let system_data = system_data_vec.first().unwrap(); let system_info = SystemInfo::try_from_smbios(system_data)?; let model = system_info.product_name; let vendor = system_info.manufacturer; let architecture = to_debian_architecture(ARCH) .with_context(|| format!("cannot parse architecture {ARCH:?}"))? .to_owned(); let os = OS::try_new( os_release_filepath.as_path(), proc_version_filepath.as_path(), runner, ) .context("cannot read OS release information")?; let pci_peripherals = Vec::new(); let usb_peripherals = Vec::new(); Ok(Self { architecture, bios, board, chassis, model, os, pci_peripherals, processor, usb_peripherals, vendor, }) } #[cfg(not(target_arch = "x86_64"))] fn from(paths: Paths, runner: &impl CommandRunner) -> Result { let Paths { cpuinfo_filepath, max_cpu_frequency_filepath, device_tree_dirpath, os_release_filepath, proc_version_filepath, .. } = paths; let cpu_info = CpuInfo::from_file(&cpuinfo_filepath.clone())?; let architecture = to_debian_architecture(ARCH) .with_context(|| format!("cannot parse architecture {ARCH:?}"))? .to_owned(); let bios = None; let board = Board::try_from(device_tree_dirpath.as_path())?; let chassis = None; let model = cpu_info.model; let os = OS::try_new( os_release_filepath.as_path(), proc_version_filepath.as_path(), runner, )?; let pci_peripherals = Vec::new(); let processor = Processor::try_from(( cpuinfo_filepath.as_path(), max_cpu_frequency_filepath.as_path(), ))?; let usb_peripherals = Vec::new(); let vendor = String::from("Unknown"); Ok(Self { architecture, bios, board, chassis, model, os, pci_peripherals, processor, usb_peripherals, vendor, }) } } #[cfg(test)] mod tests { use crate::{ constants, helpers::test_utils::{apply_vars, get_test_filepath, MockCommandRunner}, models::request_validators::{CertificationStatusRequest, Paths}, }; use serde_json::Value; use simple_test_case::test_case; use std::{fs::read_to_string, path::PathBuf}; /// Test how certification request is prepared for the data collected /// from SMBios #[test_case( "amd64/dgx_station", "jammy", "22.04", "5.4.0-192-generic", &["nvme", "intel_lpss_pci", "intel_ish_ipc", "idma64"]; "jammy_dgx_station" )] #[test_case( "amd64/dell_xps13", "noble", "24.04", "6.8.0-1013-oem", &["zfs", "spl", "nvme_tcp"]; "noble_dell_xps13" )] #[test_case( "amd64/thinkstation_p620", "focal", "20.04", "5.15.0-125-generic", &["xt_tcpudp", "nft_chain_nat"]; "focal_thinkstation" )] #[test] fn test_smbios_certification_request( dir_path: &str, codename: &str, release: &str, kernel_version: &str, kernel_modules: &[&str], ) { let paths = Paths { smbios_entry_filepath: get_test_filepath( format!("{dir_path}/smbios_entry_point").as_str(), ), smbios_table_filepath: get_test_filepath(format!("{dir_path}/DMI").as_str()), max_cpu_frequency_filepath: get_test_filepath( format!("{dir_path}/cpuinfo_max_freq").as_str(), ), os_release_filepath: get_test_filepath(format!("{dir_path}/os-release").as_str()), proc_version_filepath: get_test_filepath(format!("{dir_path}/version").as_str()), cpuinfo_filepath: PathBuf::from("./none"), device_tree_dirpath: PathBuf::from("./none"), }; let lsmod_output: String = std::iter::once("Module Size Used by\n".to_owned()) .chain( kernel_modules .iter() .map(|module| format!("{module} 456092 0\n")), ) .collect::(); let mock_calls = vec![((constants::LSMOD, Vec::new()), Ok(lsmod_output.as_str()))]; let mock_runner = MockCommandRunner::new(mock_calls); let quoted_kernel_modules: Vec<_> = kernel_modules .iter() .map(|module| format!("\"{module}\"")) .collect(); let kernel_modules_str = format!("[{}]", quoted_kernel_modules.join(", ")); let content = read_to_string(get_test_filepath( format!("{dir_path}/request.json").as_str(), )) .unwrap(); let expected_result = apply_vars( content, &[ ("CODENAME", codename), ("KERNEL_VERSION", kernel_version), ("KERNEL_MODULES", kernel_modules_str.as_str()), ("RELEASE", release), ], ); let cert_status_request_json = serde_json::to_value( CertificationStatusRequest::new_with_runner(paths, &mock_runner).unwrap(), ) .unwrap(); let expected_json: Value = serde_json::from_str(expected_result.as_str()).expect("JSON was not well formatted"); assert_eq!(cert_status_request_json, expected_json); } } hwlib-0.10.0/src/models/response_validators.rs000064400000000000000000000037531046102023000175250ustar 00000000000000/* Copyright 2024 Canonical Ltd. * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 3, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Written by: * Nadzeya Hutsko */ use serde::{Deserialize, Serialize}; use crate::models::{ devices::{ Audio, Bios, Board, Chassis, NetworkAdapter, PCIPeripheral, USBPeripheral, VideoCapture, WirelessAdapter, GPU, }, software::OS, }; #[derive(Serialize, Deserialize, Debug)] #[serde(tag = "status")] pub enum CertificationStatusResponse { Certified { architecture: String, available_releases: Vec, bios: Bios, board: Board, chassis: Option, }, #[serde(rename = "Not Seen")] NotSeen, #[serde(rename = "Certified Image Exists")] CertifiedImageExists { architecture: String, bios: Bios, board: Board, available_releases: Vec, chassis: Option, }, #[serde(rename = "Related Certified System Exists")] RelatedCertifiedSystemExists { architecture: String, board: Board, bios: Bios, chassis: Option, gpu: Option>, audio: Option>, video: Option>, network: Option>, wireless: Option>, pci_peripherals: Vec, usb_peripherals: Vec, available_releases: Vec, }, } hwlib-0.10.0/src/models/software.rs000064400000000000000000000022021046102023000152550ustar 00000000000000/* Copyright 2024 Canonical Ltd. * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 3, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Written by: * Nadzeya Hutsko */ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct KernelPackage { pub name: Option, pub version: String, pub signature: Option, pub loaded_modules: Vec, } #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct OS { pub codename: String, pub distributor: String, pub version: String, pub kernel: KernelPackage, } hwlib-0.10.0/src/py_bindings.rs000064400000000000000000000041311046102023000144500ustar 00000000000000/* Copyright 2024 Canonical Ltd. * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 3, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Written by: * Nadzeya Hutsko */ use crate::{ models::request_validators::{CertificationStatusRequest, Paths}, send_certification_status_request as native_send_certification_status_request, }; use pyo3::{ exceptions::PyRuntimeError, prelude::*, types::PyString, wrap_pyfunction, {PyObject, PyResult, Python}, }; use serde_json; /// This function creates and sends the certification status request to the specified /// hardware-api server URL. #[pyfunction] fn send_certification_request(py: Python, url: String) -> PyResult { let request_body = CertificationStatusRequest::new(Paths::default()) .map_err(|e| PyRuntimeError::new_err(format!("failed to create request: {e}")))?; let response = native_send_certification_status_request(url, &request_body); match response { Ok(response_value) => { let json_str = serde_json::json!(response_value).to_string(); let json: PyObject = PyString::new(py, &json_str).into(); let json_module = py.import("json")?; let json_object: PyObject = json_module.call_method1("loads", (json,))?.into(); Ok(json_object) } Err(e) => Err(PyErr::new::(format!( "Request failed: {e}" ))), } } #[pymodule] fn hwlib(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(send_certification_request, m)?)?; Ok(()) } hwlib-0.10.0/test_data/README.md000064400000000000000000000066071046102023000142470ustar 00000000000000# Test Data Directory This example data serves two purposes: - provides a comprehensive set of example data against which unit and/or component tests can be run - serve as a means of demonstrating to interested parties exactly what data the library collects and is transmitted to the hardware API server. All fields should be non-uniquely indentifiable to ensure that they tracking or tracing of machines interacting with service is possible Currently, the project uses test data of the following machines: - NVIDIA DGX-Station: [ubuntu.com/certified/201711-25989](https://ubuntu.com/certified/201711-25989) - Lenovo ThinkStation P620: [ubuntu.com/certified/202203-30052](https://ubuntu.com/certified/202203-30052) - Dell XPS 13 9340: [ubuntu.com/certified/202405-34051](https://ubuntu.com/certified/202405-34051) - Raspberry Pi 4 Model B 8 GB: [ubuntu.com/certified/202004-27865](https://ubuntu.com/certified/202004-27865) ## Structure Overview The `test_data` directory has the following structure: ``` ├── │   ├── │   │   ├── │   │   └── request.json ``` Key Files: - `cpuinfo_max_freq` — Contains maximum CPU frequency data. Can be fetched from `/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq` - `DMI` — DMI table data, can be retrieved from the `/sys/firmware/dmi/tables/` directory. - `smbios_entry_point` — SMBIOS entry point details. Is located in the `/sys/firmware/dmi/tables/` directory. - `version` — Kernel version file (`/proc/version`). - `request.json` — Expected request body that should be constructed. - `cpuinfo` — CPU information, see `/proc/cpuinfo`. If used only for non-amd64 machine. - `device-tree/` (dir) — arm64 specific directory with system information. See `/proc/device-tree`. ## Adding New Test Cases 1. Create a new directory under `amd64/` or `generic/` based on your test requirements. 2. Populate it with the necessary files (`cpuinfo_max_freq`, `DMI`, etc.). **Make sure you replace all the sensitive data like serial numbers with zeroes.** You can use the [`sed`](https://man7.org/linux/man-pages/man1/sed.1.html) tool for it. 3. Add `request.json` with anticipated values to validate against. Replace the values that you want to use variable with placeholders, for example: ``` "os": { "codename": "$CODENAME", "distributor": "Ubuntu", "kernel": { "loaded_modules": $KERNEL_MODULES, "name": "Linux", "signature": null, "version": "$KERNEL_VERSION" }, "version": "$RELEASE" } ``` In this example, we replace values in the quotes with strings defined in the test cases, and `$KERNEL_MODULES` gets replaced with a dict. This is how the test case is defined (see tests in the [models/request_validators.rs](../src/models/request_validators.rs) for more): ```rust #[test_case( "amd64/thinkstation_p620", // dir name "focal", // Ubuntu release codename "20.04", // The release itself "5.15.0-125-generic", // kernel version from the {dir_name}/version file &["xt_tcpudp", "nft_chain_nat"]; // kernel modules "focal_thinkstation" // test case name )] ``` 4. If you're adding a test case for a certified machine, update this document to include link to the machine on [ubuntu.com/certified](https://ubuntu.com/certified). hwlib-0.10.0/test_data/amd64/dell_xps13/DMI000064400000000000000000000155131046102023000162110ustar 00000000000000ڲ|P""##(())**++,,PPUUmm}}  ++,,558899DDEEJJKKLLRRڲ|PSShhiiKKLLddeeffgghhiillmmڲ|P  &&++,,AABBCCFFGGHHIIJJMMNNOOPPaabbddeeggllmmnnttuuڲ|Pxxyy11223366778899@@AABBCCDDEEFFGGKKLLڲ|PMMNNOOQQRRSSTTaabb{{||ڲ|P,,0011GGHHNNOOXXYYZZ[[\\]]^^__``eemmnnrrssttwwJ@J@K@K@L@L@O@O@P@P@Mڲ|Pqڲ|P ""0022@@BBPPRR < @Dell Inc.1.7.006/12/2024DELLT9SO9Y3XPSDell Inc.XPS 13 93400C870000000  Dell Inc.02395CX04/0000000/00000000000000/ Dell Inc.0000000Notebook2 dAU3E1Intel(R) CorporationIntel(R) Core(TM) Ultra 7 155H      L1 Cache L1 Cache00 00L2 Cache``  ``L3 Cache@@ @@L1 Cache L1 Cache L2 Cache``  ``L3 Cache  KeyboardNone MouseNone NoneUSB1 NoneUSB2 J9A1 - TPM/PORT 80None J8E1 - SPI ProgramNone J5J1 - FP HeaderNone J1H2 - BATT ANone J2G1 - CPU FanNone J4C1 - FAN PWRNone   PCI-Express 0  PCI-Express 1  PCI-Express 2  PCI-Express 3  PCI-Express 4  PCI-Express 5  PCI-Express 6  Dell System1[0C87]3[1.0]12[www.dell.com]14[1]15[0]27[21360995931]34[Feature - 100]  J6H1:1-X Boot with Default; J8H1:1-X BIOS RECOVERY  enUS$MEIFirmware Version Info\ #++MotherboardBANK 0 K3KLALA0CM-MGCT \ #++MotherboardBANK 1 K3KLALA0CM-MGCT \ #++MotherboardBANK 2 K3KLALA0CM-MGCT \ #++MotherboardBANK 3 K3KLALA0CM-MGCT \ #++MotherboardBANK 0 K3KLALA0CM-MGCT \ #++MotherboardBANK 1 K3KLALA0CM-MGCT \ #++MotherboardBANK 2 K3KLALA0CM-MGCT \ #++MotherboardBANK 3 K3KLALA0CM-MGCT %-%W Sys. Battery BayBYD09/05/202300CADELL TR7FC3951.0LiPCN0TR7FCBDS00395506UA00  cxProcessor FancLVideo Fan eCooling Device 1 qCooling Device 2i dCPUg dSKINh dDIMM Ag dSKINg dSKINg dSKIN '' ) ) ) ) ) ) ) ) ++NTCTPM 2.0, ManufacturerID: NTC , Firmware Version: 0x00070002.0x0$AMT@5~1 ]&vPro,xM A98bc &arW \ ; < = >&?@ABCHP !" 1[0000000000000000000000000000000000000000000000000000000000000000]jUi0MEI1MEI2MEI3MEI4 BIOS Guard FSP Binary Version0D.00.0097.0010 Reference Code - CPUuCode VersionTXT ACM version ]Reference Code - MEME Firmware VersionCorporate SKUISSE Version03E8.0000.0005.0733/   FReference Code - PCHPCH-CRID StatusDisabledPCH-CRID Original ValuePCH-CRID New ValueOPROM - RST - RAIDPCH Hsio VersionR    0 e  Reference Code - SA - System AgentReference Code - MRCSA - PCIe VersionSA-CRID StatusDisabledSA-CRID Original ValueSA-CRID New ValueOPROM - VBIOSIO Manageability Engine FW VersionPHY Build VersionThunderbolt(TM) FW VersionSystem Agent Manageability Engine FW Versionu  "5 Lan Phy VersionSensor Firmware VersionDebug Mode StatusDisabledPerformance Mode StatusDisabledDebug Use USB(Disabled:Serial)DisabledICC Overclocking VersionUNDI VersionEC FW VersionGOP VersionRoyal Park VersionPlatform VersionTCSS PD0 VersionTCSS PD1 VersionTCSS Retimer0 VersionTCSS Retimer1 VersionTCSS Retimer2 Version 2023102520231030 "Intel Corp.""2089"US-101Proprietary "02@BPR$_SIDARmihAmyVZaZ0C87hwlib-0.10.0/test_data/amd64/dell_xps13/cpuinfo_max_freq000064400000000000000000000000101046102023000211070ustar 000000000000004500000 hwlib-0.10.0/test_data/amd64/dell_xps13/os-release000064400000000000000000000006201046102023000176300ustar 00000000000000PRETTY_NAME="Ubuntu 24.04.2 LTS" NAME="Ubuntu" VERSION_ID="24.04" VERSION="24.04.2 LTS (Noble Numbat)" VERSION_CODENAME=noble ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=noble LOGO=ubuntu-logo hwlib-0.10.0/test_data/amd64/dell_xps13/request.json000064400000000000000000000017611046102023000202400ustar 00000000000000{ "architecture": "amd64", "bios": { "firmware_revision": "1.7", "release_date": "06/12/2024", "revision": "1.7.0", "vendor": "Dell Inc.", "version": "1.7.0" }, "board": { "manufacturer": "Dell Inc.", "product_name": "02395C", "version": "X04" }, "chassis": { "chassis_type": "Notebook", "manufacturer": "Dell Inc.", "sku": "Notebook", "version": "" }, "model": "XPS 13 9340", "os": { "codename": "$CODENAME", "distributor": "Ubuntu", "kernel": { "loaded_modules": $KERNEL_MODULES, "name": "Linux", "signature": null, "version": "$KERNEL_VERSION" }, "version": "$RELEASE" }, "pci_peripherals": [], "processor": { "frequency": 4500, "identifier": [ 164, 6, 10, 0, 255, 251, 235, 191 ], "manufacturer": "Intel(R) Corporation", "version": "Intel(R) Core(TM) Ultra 7 155H" }, "usb_peripherals": [], "vendor": "Dell Inc." } hwlib-0.10.0/test_data/amd64/dell_xps13/response.json000064400000000000000000000011051046102023000203760ustar 00000000000000{ "status": "Certified", "architecture": "amd64", "bios": { "vendor": "Dell", "version": "1.7.0", "revision": null, "firmware_revision": "1.9", "release_date": null }, "board": { "manufacturer": "Dell", "product_name": "02395C", "version": "X04" }, "chassis": null, "available_releases": [ { "distributor": "Ubuntu", "version": "24.04", "codename": "noble", "kernel": { "name": null, "version": "6.8.0-1009-oem", "signature": null, "loaded_modules": [] } } ] } hwlib-0.10.0/test_data/amd64/dell_xps13/smbios_entry_point000064400000000000000000000000371046102023000215210ustar 00000000000000_SM__DMI_KPMf6hwlib-0.10.0/test_data/amd64/dell_xps13/version000064400000000000000000000003241046102023000172570ustar 00000000000000Linux version 6.8.0-1013-oem (buildd@lcy02-amd64-046) (x86_64-linux-gnu-gcc-13 (Ubuntu 13.2.0-23ubuntu4) 13.2.0, GNU ld (GNU Binutils for Ubuntu) 2.42) #13-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 6 14:37:50 UTC 2024 hwlib-0.10.0/test_data/amd64/dgx_station/DMI000064400000000000000000000106411046102023000165530ustar 00000000000000?  American Megatrends Inc.040608/27/2018E `[aC$,MTGn#NVIDIADGX StationSystem Version0000000000000920-22587-2510-000DGX  EMPTYX99-E-10G WSRev 1.xx000000000000000Default stringDefault stringEMPTYDefault stringDefault stringDefault stringDefault string USB3_E12USB3_E12 USB3_E34USB3_E34 USB7~10USB7~10 USB3.1_EA34USB3.1_EA34 USB3.1_EA1USB3.1_EA1 USB3.1_EC2USB3.1_EC2  LAN1LAN1  LAN2LAN2 AUDIOAUDIO " SATA6G_12 " SATA6G_34 " SATA6G_56 " SATA6G_78 " SATA6G_9 " SATA6G_10 " SATAEXPRESS_1 " SATAEXPRESS_E1 " M.2(SOCKET3) " U.2_1 " U.2_2 USB3_12 USB3_34 USB1112 TPM SPDIF_OUT AAFP CPU_FAN CPU_OPT CHA_FAN1 !CHA_FAN2 "EXT_FAN #H_AMP_FAN $W_PUMP %TB_HEADER &RGB_HEADER '   PCIEX16_1 ( PCIEX1_1 )  PCIEX16_2 *  PCIEX16_3 +  PCIEX16_4 ,  PCIEX16_5 - To Be Filled By O.E.M. .Default stringDefault stringDefault stringDefault string /Default string 0" 1UNKNOWN2LM78A$3# 4112Default string5LM78A$6# 7145Default string85Cooling Dev 1$9# :178Default string;5$<# =1:;Default string>ABC$?# @1=;Default string"AUNKNOWN-2BLM78B$C # DAABDefault stringELM78B$F # GADEDefault stringHLM78B$I# JAGHDefault stringKHCooling Dev 2$L# MAJKDefault stringNLM78B$O# PAMNDefault stringQNCooling Dev 2$R# SAPQDefault stringTDEF$U# VASQDefault stringWGHI$X# YAVQDefault stringZjLM78A[jLM78A\[gCooling Dev 1]jABC'^Z\]To Be Filled By O.E.M.To Be Filled By O.E.M.To Be Filled By O.E.M.To Be Filled By O.E.M.To Be Filled By O.E.M.To Be Filled By O.E.M.To Be Filled By O.E.M.) _ Onboard IGD) ` Onboard LAN) a Onboard 1394bcb(dbHH ` ` DIMM_A1NODE 1Samsung00000000DIMM_A1_AssetTagM393A4K40BB1-CRC #edc(fbHH ` ` DIMM_A2NODE 1Samsung00000000DIMM_A2_AssetTagM393A4K40BB1-CRC #gfc(hbHH ` ` DIMM_B1NODE 1Samsung00000000DIMM_B1_AssetTagM393A4K40BB1-CRC #ihc(jbHH ` ` DIMM_B2NODE 1Samsung00000000DIMM_B2_AssetTagM393A4K40BB1-CRC #kjclml(nlHH ` ` DIMM_C1NODE 2Samsung00000000DIMM_C1_AssetTagM393A4K40BB1-CRC #o nm(plHH ` ` DIMM_C2NODE 2Samsung00000000DIMM_C2_AssetTagM393A4K40BB1-CRC #q pm(rlHH ` ` DIMM_D1NODE 2Samsung00000000DIMM_D1_AssetTagM393A4K40BB1-CRC #s rm(tlHH ` ` DIMM_D2NODE 2Samsung00000000DIMM_D2_AssetTagM393A4K40BB1-CRC #utmvCPU Internal L1wCPU Internal L2x CPU Internal L3*ydA+vwx(SOCKET 2011IntelIntel(R) Xeon(R) CPU E5-2698 v4 @ 2.20GHzz$AMT/@{G %vPro | en|US|iso8859-1fr|FR|iso8859-1zh|CNT|unicodezh|CNS|unicodeja|JP|unicodede|DE|iso8859-1es|ES|iso8859-1ru|RU|iso8859-5ko|KR|unicode}hwlib-0.10.0/test_data/amd64/dgx_station/cpuinfo_max_freq000064400000000000000000000000071046102023000214620ustar 00000000000000800000 hwlib-0.10.0/test_data/amd64/dgx_station/os-release000064400000000000000000000006231046102023000202000ustar 00000000000000PRETTY_NAME="Ubuntu 22.04.2 LTS" NAME="Ubuntu" VERSION_ID="22.04" VERSION="22.04.2 LTS (Jammy Jellyfish)" VERSION_CODENAME=jammy ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=jammy LOGO=ubuntu-logo hwlib-0.10.0/test_data/amd64/dgx_station/request.json000064400000000000000000000020141046102023000205750ustar 00000000000000{ "architecture": "amd64", "bios": { "firmware_revision": "5.11", "release_date": "08/27/2018", "revision": "0406", "vendor": "American Megatrends Inc.", "version": "0406" }, "board": { "manufacturer": "EMPTY", "product_name": "X99-E-10G WS", "version": "Rev 1.xx" }, "chassis": { "chassis_type": "Desktop", "manufacturer": "EMPTY", "sku": "Default string", "version": "Default string" }, "model": "DGX Station", "os": { "codename": "$CODENAME", "distributor": "Ubuntu", "kernel": { "loaded_modules": $KERNEL_MODULES, "name": "Linux", "signature": null, "version": "$KERNEL_VERSION" }, "version": "$RELEASE" }, "pci_peripherals": [], "processor": { "frequency": 800, "identifier": [ 241, 6, 4, 0, 255, 251, 235, 191 ], "manufacturer": "Intel", "version": "Intel(R) Xeon(R) CPU E5-2698 v4 @ 2.20GHz" }, "usb_peripherals": [], "vendor": "NVIDIA" } hwlib-0.10.0/test_data/amd64/dgx_station/response.json000064400000000000000000000021101046102023000207400ustar 00000000000000{ "status": "Certified", "architecture": "amd64", "bios": { "vendor": "American Megatrends Inc.", "version": "0406", "revision": null, "firmware_revision": null, "release_date": null }, "board": { "manufacturer": "empty", "product_name": "X99-E-10G WS", "version": "Rev 1.xx" }, "chassis": null, "available_releases": [ { "distributor": "Ubuntu", "version": "22.04", "codename": "jammy", "kernel": { "name": null, "version": "5.15.0-1028-nvidia", "signature": null, "loaded_modules": [] } }, { "distributor": "Ubuntu", "version": "20.04", "codename": "focal", "kernel": { "name": null, "version": "5.4.0-26-generic", "signature": null, "loaded_modules": [] } }, { "distributor": "Ubuntu", "version": "18.04", "codename": "bionic", "kernel": { "name": null, "version": "5.3.0-51-generic", "signature": null, "loaded_modules": [] } } ] } hwlib-0.10.0/test_data/amd64/dgx_station/smbios_entry_point000064400000000000000000000000301046102023000220570ustar 00000000000000_SM3_:еhwlib-0.10.0/test_data/amd64/dgx_station/version000064400000000000000000000002311046102023000176210ustar 00000000000000Linux version 5.4.0-192-generic (buildd@lcy02-amd64-036) (gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.2)) #212-Ubuntu SMP Fri Jul 5 09:47:39 UTC 2024 hwlib-0.10.0/test_data/amd64/questing_vm/DMI000064400000000000000000000006321046102023000165700ustar 000000000000008ہAww ,$QEMUStandard PC (Q35 + ICH9, 2009)pc-q35-8.2 Canonical Ltd.LXDpc-q35-8.2QEMUpc-q35-8.20AACPU 0QEMUpc-q35-8.2( DIMM 0QEMU EDK IIunknown2/2/98hwlib-0.10.0/test_data/amd64/questing_vm/smbios_entry_point000064400000000000000000000000301046102023000220750ustar 00000000000000_SM3_V?hwlib-0.10.0/test_data/amd64/thinkstation_p620/DMI000064400000000000000000000106431046102023000175200ustar 00000000000000 A LENOVOS07KT41A11/29/2021LENOVOThinkStation P620ThinkStation P620000000000000LENOVO_MT_Thin_BU_Think_FM_ThinkStation P620+INVALID  LENOVO1046Not Defined Default stringLENOVONone Default string  To Be Filled By O.E.M. LENOVO ThinkStation Embedded Controller -[S07ES13A-1.13]-LENOVO ThinkStation BIOS Boot Block Revision 1.41INVALIDINVALIDINVALIDINVALIDINVALIDINVALIDINVALIDINVALIDINVALIDINVALIDINVALIDINVALIDINVALID scre++SMI:00B2C000 " LM78-1 gVTT g3VCC g5VCC g12VCCg3VSBcCPU_SensorcCPU_VR_SensorgAmbientgIO HubgPCIE_ZONE1_SENSORgPCIE_ZONE2_SENSORgPCIE_ZONE3_SENSORgM2_SensorjPSU_SensorgCooling Dev 1jABC'To Be Filled By O.E.M.To Be Filled By O.E.M.To Be Filled By O.E.M.To Be Filled By O.E.M.To Be Filled By O.E.M.To Be Filled By O.E.M.To Be Filled By O.E.M., +IFXUTPM 2.0INFINEONL1 - CacheL2 - Cache L3 - Cache0!kd0<A7  k SP3Advanced Micro Devices, Inc.AMD Ryzen Threadripper PRO 3945WX 12-Cores UnknownUnknownUnknown"#@"$/#%@#&\'#&DIMM5BANK4UnknownUnknownUnknownUnknown(\)#(DIMM6BANK5UnknownUnknownUnknownUnknown*\+#*H@@   DIMM7BANK6Hynix00000000HMA82GR7CJR8N-XN Unknown#,+%-\.#-H@@   DIMM8BANK7Hynix00000000HMA82GR7CJR8N-XN Unknown#/.%0\1#0DIMM4BANK3UnknownUnknownUnknownUnknown2\3#2DIMM3BANK2UnknownUnknownUnknownUnknown4\5#4DIMM2BANK1UnknownUnknownUnknownUnknown6\7#6DIMM1BANK0UnknownUnknownUnknownUnknown=KHOIHGIUCCHHII>LENOVO MS ?LENOVO S07ES13A06/18/2021 @J1603USB3.1 G2 TypeA AJ1602USB3.1 G2 TypeC BJ1601USB3.1 G2 TypeC CJ1600USB3.1 G2 TypeA DJ1300USB3.1 G2 E J1300RJ45 F J2000RJ45 GJ1503USB3.1 G2 HJ1502USB3.1 G2 IJ2100Audio Jack JJ4306 - MEM FAN KJ3000 - ATX PWR LJ4300 - SYSTEM FAN MJ4305 - CPU FAN NJ3001 - ATX 12V PWR OJ4301 - MEM FAN PJ3002 - ATX 24PIN PWR Q J1800 - iSATA R J1801 - iSATA S J1802 - iSATA T J1803 - iSATA UJ604 - SMA100M_CLKIN_N SMA Jack VJ4304 - X570/X590 FAN WJ202 - LPC HDR X   J6009 Y  J6006 Z  J6005 [  J6007 \  J6008 ]   J3603 ^   J6001 _  @ J6002 `  @J6000 a  ` J3601 b  `J6004 c  `J6003dTVT-EnablementIeǯ    fen|US|iso8859-1fr|FR|iso8859-1zh|CN|unicodehhwlib-0.10.0/test_data/amd64/thinkstation_p620/cpuinfo_max_freq000064400000000000000000000000101046102023000224170ustar 000000000000004402734 hwlib-0.10.0/test_data/amd64/thinkstation_p620/os-release000064400000000000000000000006171046102023000211460ustar 00000000000000PRETTY_NAME="Ubuntu 20.04.2 LTS" NAME="Ubuntu" VERSION_ID="20.04" VERSION="20.04.2 LTS (Focal Fossa)" VERSION_CODENAME=focal ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=focal LOGO=ubuntu-logo hwlib-0.10.0/test_data/amd64/thinkstation_p620/request.json000064400000000000000000000020571046102023000215470ustar 00000000000000{ "architecture": "amd64", "bios": { "firmware_revision": "1.65", "release_date": "11/29/2021", "revision": "S07KT41A", "vendor": "LENOVO", "version": "S07KT41A" }, "board": { "manufacturer": "LENOVO", "product_name": "1046", "version": "Not Defined " }, "chassis": { "chassis_type": "Desktop", "manufacturer": "LENOVO", "sku": "Default string", "version": "None" }, "model": "ThinkStation P620", "os": { "codename": "$CODENAME", "distributor": "Ubuntu", "kernel": { "loaded_modules": $KERNEL_MODULES, "name": "Linux", "signature": null, "version": "$KERNEL_VERSION" }, "version": "$RELEASE" }, "pci_peripherals": [], "processor": { "frequency": 4402, "identifier": [ 16, 15, 131, 0, 255, 251, 139, 23 ], "manufacturer": "Advanced Micro Devices, Inc.", "version": "AMD Ryzen Threadripper PRO 3945WX 12-Cores " }, "usb_peripherals": [], "vendor": "LENOVO" } hwlib-0.10.0/test_data/amd64/thinkstation_p620/response.json000064400000000000000000000011261046102023000217110ustar 00000000000000{ "status": "Certified", "architecture": "amd64", "bios": { "vendor": "Lenovo", "version": "S07KT41A", "revision": null, "firmware_revision": "1.19", "release_date": null }, "board": { "manufacturer": "Lenovo", "product_name": "1046", "version": "Not Defined" }, "chassis": null, "available_releases": [ { "distributor": "Ubuntu", "version": "20.04", "codename": "focal", "kernel": { "name": null, "version": "5.15.0-48-generic", "signature": null, "loaded_modules": [] } } ] } hwlib-0.10.0/test_data/amd64/thinkstation_p620/smbios_entry_point000064400000000000000000000000301046102023000230220ustar 00000000000000_SM3_Lයhwlib-0.10.0/test_data/amd64/thinkstation_p620/version000064400000000000000000000003011046102023000205620ustar 00000000000000Linux version 5.15.0-125-generic (buildd@lcy02-amd64-040) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #135~20.04.1-Ubuntu SMP Mon Oct 7 13:56:22 UTC 2024 hwlib-0.10.0/test_data/arm64/rpi4b8g/cpuinfo000064400000000000000000000022331046102023000165550ustar 00000000000000processor : 0 model name : ARMv7 Processor rev 3 (v7l) BogoMIPS : 108.00 Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 CPU implementer : 0x41 CPU architecture: 7 CPU variant : 0x0 CPU part : 0xd08 CPU revision : 3 processor : 1 model name : ARMv7 Processor rev 3 (v7l) BogoMIPS : 108.00 Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 CPU implementer : 0x41 CPU architecture: 7 CPU variant : 0x0 CPU part : 0xd08 CPU revision : 3 processor : 2 model name : ARMv7 Processor rev 3 (v7l) BogoMIPS : 108.00 Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 CPU implementer : 0x41 CPU architecture: 7 CPU variant : 0x0 CPU part : 0xd08 CPU revision : 3 processor : 3 model name : ARMv7 Processor rev 3 (v7l) BogoMIPS : 108.00 Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 CPU implementer : 0x41 CPU architecture: 7 CPU variant : 0x0 CPU part : 0xd08 CPU revision : 3 Hardware : BCM2711 Revision : d03114 Serial : 0000000000000000 Model : Raspberry Pi 4 Model B Rev 1.4hwlib-0.10.0/test_data/arm64/rpi4b8g/cpuinfo_max_freq000064400000000000000000000000061046102023000204330ustar 00000000000000600000hwlib-0.10.0/test_data/arm64/rpi4b8g/device-tree/compatible000064400000000000000000000000411046102023000214200ustar 00000000000000raspberrypi,4-model-bbrcm,bcm2711hwlib-0.10.0/test_data/arm64/rpi4b8g/device-tree/model000064400000000000000000000000361046102023000204050ustar 00000000000000Raspberry Pi 4 Model B Rev 1.5hwlib-0.10.0/test_data/arm64/rpi4b8g/os-release000064400000000000000000000006171046102023000171550ustar 00000000000000PRETTY_NAME="Ubuntu 20.04.2 LTS" NAME="Ubuntu" VERSION_ID="20.04" VERSION="20.04.2 LTS (Focal Fossa)" VERSION_CODENAME=focal ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=focal LOGO=ubuntu-logo hwlib-0.10.0/test_data/arm64/rpi4b8g/version000064400000000000000000000002411046102023000165740ustar 00000000000000Linux version 5.4.0-1119-raspi (buildd@bos03-arm64-044) (gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.2)) #131-Ubuntu SMP PREEMPT Thu Oct 10 17:30:47 UTC 2024 hwlib-0.10.0/tox.ini000064400000000000000000000004441046102023000123240ustar 00000000000000[tox] envlist = py skipsdist = true [testenv] deps = black ruff pytest maturin commands_pre = {envbindir}/maturin develop commands = {envbindir}/python -m black --check pytests/ {envbindir}/python -m ruff check pytests/ {envbindir}/python -m pytest pytests/