Repository navigation
test: property-test artifact integrity, engine protocol and the pinned release key #803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
907a561
test(integrity): property-test artifact integrity and protocol parsing
rominf 33c9297
test(release): check single-character drifts of the pinned release key
rominf b8a6bcc
test(integrity): pin alias/basename readiness matches, tighten checks
rominf 282e946
test(release): make the pinned-key tests independent of key shape
rominf 3eab903
test(support): keep one copy of the property case-count rule
rominf 5471406
test(integrity): size the multi-chunk body from the real chunk size
rominf b66cf1f
test(integrity): remove the digest gate's scratch dir on failure too
rominf ded6d17
test(release): say what the pinned-key check's punctuation gap costs
rominf 36b12e2
test(support): re-export the env-knob case count only on Unix
rominf a1365a1
Merge origin/main into test/proptest-integrity-protocol
rominf 4f97275
test(release): match the pinned-key tests to the checks main now enfo…
rominf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| // Copyright © Advanced Micro Devices, Inc., or its affiliates. | ||
| // | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| //! A loopback HTTP server for the integration tests that drive real network | ||
| //! code: it answers every request with one fixed `200 OK` until it is dropped. | ||
|
|
||
| use std::io::{Read, Write}; | ||
| use std::net::{TcpListener, TcpStream}; | ||
| use std::sync::Arc; | ||
| use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; | ||
| use std::thread; | ||
| use std::time::Duration; | ||
|
|
||
| /// Serves one fixed response on an ephemeral loopback port, to any number of | ||
| /// requests, until dropped. | ||
| /// | ||
| /// Dropping it never hangs: it wakes the accept loop with a connection of its | ||
| /// own before joining, so a client that never connected cannot leave the | ||
| /// server thread blocked in `accept`. | ||
| pub struct LoopbackServer { | ||
| port: u16, | ||
| stopping: Arc<AtomicBool>, | ||
| served: Arc<AtomicUsize>, | ||
| handle: Option<thread::JoinHandle<()>>, | ||
| } | ||
|
|
||
| impl LoopbackServer { | ||
| pub fn start(content_type: Option<&str>, body: Vec<u8>) -> Self { | ||
| let listener = TcpListener::bind("127.0.0.1:0").expect("bind loopback"); | ||
| let port = listener.local_addr().expect("local addr").port(); | ||
| let stopping = Arc::new(AtomicBool::new(false)); | ||
| let served = Arc::new(AtomicUsize::new(0)); | ||
| let content_type = content_type | ||
| .map(|value| format!("Content-Type: {value}\r\n")) | ||
| .unwrap_or_default(); | ||
| let handle = thread::spawn({ | ||
| let stopping = Arc::clone(&stopping); | ||
| let served = Arc::clone(&served); | ||
| move || { | ||
| for stream in listener.incoming() { | ||
| if stopping.load(Ordering::SeqCst) { | ||
| break; | ||
| } | ||
| let Ok(mut stream) = stream else { continue }; | ||
| // A client that connects and never sends cannot hold the | ||
| // accept loop, and with it `Drop`, forever. | ||
| let _ = stream.set_read_timeout(Some(Duration::from_secs(10))); | ||
| read_request_head(&mut stream); | ||
| // Counted before the response is written, so a client that | ||
| // has its answer always sees its request counted. | ||
| served.fetch_add(1, Ordering::SeqCst); | ||
| let _ = write!( | ||
| stream, | ||
| "HTTP/1.1 200 OK\r\n{content_type}Content-Length: {}\r\nConnection: close\r\n\r\n", | ||
| body.len() | ||
| ); | ||
| let _ = stream.write_all(&body); | ||
| let _ = stream.flush(); | ||
| } | ||
| } | ||
| }); | ||
| Self { | ||
| port, | ||
| stopping, | ||
| served, | ||
| handle: Some(handle), | ||
| } | ||
| } | ||
|
|
||
| pub fn url(&self) -> String { | ||
| format!("http://127.0.0.1:{}", self.port) | ||
| } | ||
|
|
||
| /// Requests answered so far. A test that expects a verdict about the | ||
| /// response checks this is non-zero, so a request that never reached the | ||
| /// server cannot pass as one the code under test rejected. | ||
| pub fn requests_served(&self) -> usize { | ||
| self.served.load(Ordering::SeqCst) | ||
| } | ||
| } | ||
|
|
||
| impl Drop for LoopbackServer { | ||
| fn drop(&mut self) { | ||
| self.stopping.store(true, Ordering::SeqCst); | ||
| // Wake the accept loop so it sees the flag. If even that connection | ||
| // fails, leave the thread detached rather than block on it. | ||
| let woken = TcpStream::connect(("127.0.0.1", self.port)).is_ok(); | ||
| if let Some(handle) = self.handle.take() | ||
| && woken | ||
| { | ||
| let _ = handle.join(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Read the request line and headers, so the response is not written into a | ||
| /// request still being sent. | ||
| fn read_request_head(stream: &mut TcpStream) { | ||
| let mut head = Vec::new(); | ||
| let mut chunk = [0_u8; 1024]; | ||
| while !head.windows(4).any(|window| window == b"\r\n\r\n") && head.len() < 64 * 1024 { | ||
| match stream.read(&mut chunk) { | ||
| Ok(0) | Err(_) => break, | ||
| Ok(read) => head.extend_from_slice(&chunk[..read]), | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Copyright © Advanced Micro Devices, Inc., or its affiliates. | ||
| // | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| //! The case-count rule for property tests that set their own count. This file | ||
| //! is its one implementation: `rocm`'s and `rocm-core`'s crate-internal | ||
| //! `test_support`, the `rocm-core` and `rocm-engine-protocol` integration | ||
| //! tests, and the Lemonade engine's unit tests all include it by `#[path]`. | ||
| //! `archive_props::run_property` applies the same rule inline, since that file | ||
| //! is itself included by `#[path]` into three crates. | ||
|
|
||
| /// Case count for a property test: `PROPTEST_CASES` (proptest's own knob, | ||
| /// which an explicit count would otherwise override) when it is set and above | ||
| /// `default`, otherwise `default`. | ||
| /// | ||
| /// Never below `default`: each count is chosen so its property reaches the | ||
| /// cases it targets, and some of those are hit by a small share of cases, so a | ||
| /// lower count would pass with the defect present. `PROPTEST_CASES=0` would | ||
| /// otherwise pass every property without running one. | ||
| pub fn proptest_cases(default: u32) -> u32 { | ||
| case_count_from_env("PROPTEST_CASES", default) | ||
| } | ||
|
|
||
| /// Case count read from `var`, raising `default` but never lowering it, for | ||
| /// the same reason as [`proptest_cases`]. `rocm`'s uninstall properties use it | ||
| /// with their own knob, `ROCM_DELETION_PROP_CASES`. A value that is ignored, | ||
| /// because it is lower or does not parse, is reported on stderr. | ||
| pub fn case_count_from_env(var: &str, default: u32) -> u32 { | ||
| let requested = std::env::var(var).ok(); | ||
| let cases = raised_case_count(requested.as_deref(), default); | ||
| if let Some(requested) = requested | ||
| && requested.parse::<u32>().ok() != Some(cases) | ||
| { | ||
| eprintln!("{var}={requested} ignored: this property runs at least {default} cases"); | ||
| } | ||
| cases | ||
| } | ||
|
|
||
| /// The pure half of [`case_count_from_env`]: `requested` raises `default` and | ||
| /// never lowers it. | ||
| pub fn raised_case_count(requested: Option<&str>, default: u32) -> u32 { | ||
| requested | ||
| .and_then(|value| value.parse().ok()) | ||
| .map_or(default, |requested: u32| requested.max(default)) | ||
| } | ||
|
|
||
| #[test] | ||
| fn proptest_cases_can_raise_the_default_but_never_lower_it() { | ||
| assert_eq!(raised_case_count(None, 24), 24); | ||
| assert_eq!(raised_case_count(Some("1000"), 24), 1000); | ||
| assert_eq!(raised_case_count(Some("0"), 24), 24); | ||
| assert_eq!(raised_case_count(Some("8"), 24), 24); | ||
| assert_eq!(raised_case_count(Some("lots"), 24), 24); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.