Skip to content

Commit e8abc34

Browse files
committed
feat: mark some documentation tests as serial execution, requires explicit main()
1 parent 0a8c22d commit e8abc34

17 files changed

+135
-4
lines changed

tss-esapi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ getrandom = "0.2.11"
6767
env = "*"
6868

6969
[dev-dependencies]
70-
serial_test = "*"
70+
serial_test = { version = "*", features = ["file_locks"] }
7171
env_logger = "0.11.5"
7272
serde_json = "^1.0.108"
7373
sha2 = { version = "0.10.8", features = ["oid"] }

tss-esapi/src/abstraction/no_tpm/quote.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ fn checkquote_pcr_digests(
222222
/// # },
223223
/// # TctiNameConf,
224224
/// # };
225+
/// # #[serial_test::file_serial]
226+
/// # fn main() {
225227
/// # let mut context =
226228
/// # Context::new(
227229
/// # TctiNameConf::from_environment_variable().expect("Failed to get TCTI"),
@@ -293,6 +295,7 @@ fn checkquote_pcr_digests(
293295
/// &qualifying_data
294296
/// )
295297
/// .unwrap();
298+
/// # }
296299
/// ```
297300
pub fn checkquote(
298301
attest: &Attest,

tss-esapi/src/abstraction/pcr.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub use data::PcrData;
1515
///
1616
/// ```rust
1717
/// # use tss_esapi::{Context, TctiNameConf};
18+
/// # #[serial_test::file_serial]
19+
/// # fn main() {
1820
/// # // Create context
1921
/// # let mut context =
2022
/// # Context::new(
@@ -57,6 +59,7 @@ pub use data::PcrData;
5759
/// .expect("Failed to build PcrSelectionList");
5860
/// let _pcr_data = tss_esapi::abstraction::pcr::read_all(&mut context, pcr_selection_list)
5961
/// .expect("pcr::read_all failed");
62+
/// # }
6063
/// ```
6164
pub fn read_all(
6265
context: &mut Context,

tss-esapi/src/context.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ impl Context {
149149
/// # interface_types::algorithm::HashingAlgorithm,
150150
/// # structures::SymmetricDefinition,
151151
/// # };
152+
/// # #[serial_test::file_serial]
153+
/// # fn main() {
152154
/// # // Create context
153155
/// # let mut context =
154156
/// # Context::new(
@@ -175,6 +177,7 @@ impl Context {
175177
/// # assert_eq!(auth_session, session_1);
176178
/// # assert_eq!(None, session_2);
177179
/// # assert_eq!(None, session_3);
180+
/// # }
178181
/// ```
179182
pub fn set_sessions(
180183
&mut self,
@@ -197,6 +200,8 @@ impl Context {
197200
/// ```rust
198201
/// # use tss_esapi::{Context, tcti_ldr::TctiNameConf, interface_types::session_handles::AuthSession};
199202
/// # // Create context
203+
/// # #[serial_test::file_serial]
204+
/// # fn main() {
200205
/// # let mut context =
201206
/// # Context::new(
202207
/// # TctiNameConf::from_environment_variable().expect("Failed to get TCTI"),
@@ -210,6 +215,7 @@ impl Context {
210215
/// # assert_eq!(None, session_1);
211216
/// # assert_eq!(None, session_2);
212217
/// # assert_eq!(None, session_3);
218+
/// # }
213219
/// ```
214220
pub fn clear_sessions(&mut self) {
215221
self.sessions = (None, None, None)
@@ -221,6 +227,8 @@ impl Context {
221227
///
222228
/// ```rust
223229
/// # use tss_esapi::{Context, tcti_ldr::TctiNameConf, interface_types::session_handles::AuthSession};
230+
/// # #[serial_test::file_serial]
231+
/// # fn main() {
224232
/// # // Create context
225233
/// # let mut context =
226234
/// # Context::new(
@@ -234,6 +242,7 @@ impl Context {
234242
/// assert_eq!(Some(AuthSession::Password), session_1);
235243
/// assert_eq!(None, session_2);
236244
/// assert_eq!(None, session_3);
245+
/// # }
237246
/// ```
238247
pub fn sessions(
239248
&self,
@@ -358,6 +367,8 @@ impl Context {
358367
/// ```rust
359368
/// # use tss_esapi::{Context, tcti_ldr::TctiNameConf, constants::{PropertyTag,PrimitivePropertyTag}};
360369
/// # use std::str::FromStr;
370+
/// # #[serial_test::file_serial]
371+
/// # fn main() {
361372
/// # // Create context
362373
/// # let mut context =
363374
/// # Context::new(
@@ -367,6 +378,7 @@ impl Context {
367378
/// .get_tpm_property(PropertyTag::PrimitivePropertyTag(PrimitivePropertyTag::Revision))
368379
/// .expect("Wrong value from TPM")
369380
/// .expect("Value is not supported");
381+
/// # }
370382
/// ```
371383
pub fn get_tpm_property(&mut self, property: PropertyTag) -> Result<Option<u32>> {
372384
// Return cached value if it exists

tss-esapi/src/context/general_esys_tr.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ impl Context {
2929
/// ```rust
3030
/// # use tss_esapi::{Context, TctiNameConf};
3131
/// use tss_esapi::{handles::ObjectHandle, structures::Auth};
32+
/// # #[serial_test::file_serial]
33+
/// # fn main() {
3234
/// # // Create context
3335
/// # let mut context =
3436
/// # Context::new(
@@ -39,6 +41,7 @@ impl Context {
3941
/// context
4042
/// .tr_set_auth(ObjectHandle::Owner, Auth::default())
4143
/// .expect("Failed to call tr_set_auth");
44+
/// # }
4245
/// ```
4346
pub fn tr_set_auth(&mut self, object_handle: ObjectHandle, auth: Auth) -> Result<()> {
4447
let mut auth_value = auth.into();
@@ -67,6 +70,8 @@ impl Context {
6770
/// # interface_types::{algorithm::HashingAlgorithm, reserved_handles::Provision},
6871
/// # structures::{SymmetricDefinition, NvPublic},
6972
/// # };
73+
/// # #[serial_test::file_serial]
74+
/// # fn main() {
7075
/// # // Create context
7176
/// # let mut context =
7277
/// # Context::new(
@@ -130,6 +135,7 @@ impl Context {
130135
/// let (_public_area, expected_name) = nv_read_public_result.expect("Call to nv_read_public failed");
131136
/// let actual_name = tr_get_name_result.expect("Call to tr_get_name failed");
132137
/// assert_eq!(expected_name, actual_name);
138+
/// # }
133139
/// ```
134140
pub fn tr_get_name(&mut self, object_handle: ObjectHandle) -> Result<Name> {
135141
let mut name_ptr = null_mut();
@@ -162,6 +168,8 @@ impl Context {
162168
/// use tss_esapi::{
163169
/// handles::NvIndexTpmHandle,
164170
/// };
171+
/// # #[serial_test::file_serial]
172+
/// # fn main() {
165173
/// # // Create context
166174
/// # let mut context =
167175
/// # Context::new(
@@ -239,6 +247,7 @@ impl Context {
239247
/// # let (_, expected_name) = nv_read_public_result.expect("Call to nv_read_public failed");
240248
/// # let actual_name = tr_get_name_result.expect("Call to tr_get_name failed");
241249
/// # assert_eq!(expected_name, actual_name);
250+
/// # }
242251
/// ```
243252
pub fn tr_from_tpm_public(&mut self, tpm_handle: TpmHandle) -> Result<ObjectHandle> {
244253
let mut object = ObjectHandle::None.into();
@@ -287,6 +296,8 @@ impl Context {
287296
/// # interface_types::{algorithm::HashingAlgorithm, reserved_handles::Provision},
288297
/// # structures::{SymmetricDefinition, NvPublic},
289298
/// # };
299+
/// # #[serial_test::file_serial]
300+
/// # fn main() {
290301
/// # // Create context
291302
/// # let mut context =
292303
/// # Context::new(
@@ -359,6 +370,7 @@ impl Context {
359370
/// // Process results.
360371
/// tr_close_result.expect("Call to tr_close failed.");
361372
/// # tr_get_name_result.expect_err("Calling tr_get_name with invalid handle did not result in an error.");
373+
/// # }
362374
/// ```
363375
pub fn tr_close(&mut self, object_handle: &mut ObjectHandle) -> Result<()> {
364376
let mut rsrc_handle = object_handle.try_into_not_none()?;
@@ -423,6 +435,8 @@ impl Context {
423435
/// # },
424436
/// # structures::EccScheme,
425437
/// # };
438+
/// # #[serial_test::file_serial]
439+
/// # fn main() {
426440
/// # let mut context =
427441
/// # Context::new(
428442
/// # TctiNameConf::from_environment_variable().expect("Failed to get TCTI"),
@@ -443,6 +457,7 @@ impl Context {
443457
/// ).unwrap()
444458
/// .key_handle;
445459
/// let data = context.tr_serialize(key_handle.into()).unwrap();
460+
/// # }
446461
/// ```
447462
pub fn tr_serialize(&mut self, handle: ObjectHandle) -> Result<Vec<u8>> {
448463
let mut len = 0;
@@ -491,6 +506,8 @@ impl Context {
491506
/// # },
492507
/// # structures::EccScheme,
493508
/// # };
509+
/// # #[serial_test::file_serial]
510+
/// # fn main() {
494511
/// # let mut context =
495512
/// # Context::new(
496513
/// # TctiNameConf::from_environment_variable().expect("Failed to get TCTI"),
@@ -515,6 +532,7 @@ impl Context {
515532
/// let data = context.tr_serialize(key_handle.into()).unwrap();
516533
/// let new_handle = context.tr_deserialize(&data).unwrap();
517534
/// assert_eq!(public_key, context.read_public(new_handle.into()).unwrap());
535+
/// # }
518536
/// ```
519537
pub fn tr_deserialize(&mut self, buffer: &[u8]) -> Result<ObjectHandle> {
520538
let mut handle = TPM2_RH_UNASSIGNED;

tss-esapi/src/context/tpm_commands/asymmetric_primitives.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ impl Context {
5858
/// # },
5959
/// # };
6060
/// # use std::{env, str::FromStr, convert::TryFrom};
61+
/// # #[serial_test::file_serial]
62+
/// # fn main() {
6163
/// # // Create context
6264
/// # let mut context =
6365
/// # Context::new(
@@ -141,6 +143,7 @@ impl Context {
141143
/// # .expect("Should be possible to call rsa_decrypt using valid arguments.");
142144
/// # let decrypted_bytes = message_out.as_bytes();
143145
/// # assert_eq!(plain_text_bytes, decrypted_bytes);
146+
/// # }
144147
/// ```
145148
pub fn rsa_encrypt(
146149
&mut self,
@@ -367,6 +370,8 @@ impl Context {
367370
/// # },
368371
/// # };
369372
/// # use std::{env, str::FromStr, convert::TryFrom};
373+
/// # #[serial_test::file_serial]
374+
/// # fn main() {
370375
/// # // Create context
371376
/// # let mut context =
372377
/// # Context::new(
@@ -442,6 +447,7 @@ impl Context {
442447
///
443448
/// // Generate ephemeral key pair and a shared secret
444449
/// let (z_point, pub_point) = context.ecdh_key_gen(key_handle).unwrap();
450+
/// # }
445451
/// ```
446452
pub fn ecdh_key_gen(&mut self, key_handle: KeyHandle) -> Result<(EccPoint, EccPoint)> {
447453
let mut z_point_ptr = null_mut();
@@ -503,6 +509,8 @@ impl Context {
503509
/// # },
504510
/// # };
505511
/// # use std::{env, str::FromStr, convert::TryFrom};
512+
/// # #[serial_test::file_serial]
513+
/// # fn main() {
506514
/// # // Create context
507515
/// # let mut context =
508516
/// # Context::new(
@@ -580,6 +588,7 @@ impl Context {
580588
/// let (z_point, pub_point) = context.ecdh_key_gen(key_handle).unwrap();
581589
/// let z_point_gen = context.ecdh_z_gen(key_handle, pub_point).unwrap();
582590
/// assert_eq!(z_point.x().as_bytes(), z_point_gen.x().as_bytes());
591+
/// # }
583592
/// ```
584593
pub fn ecdh_z_gen(&mut self, key_handle: KeyHandle, in_point: EccPoint) -> Result<EccPoint> {
585594
let mut out_point_ptr = null_mut();

tss-esapi/src/context/tpm_commands/attestation_commands.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ impl Context {
6161
/// structures::{Data, SignatureScheme},
6262
/// interface_types::session_handles::AuthSession,
6363
/// };
64+
/// # #[serial_test::file_serial]
65+
/// # fn main() {
6466
/// # let mut context =
6567
/// # Context::new(
6668
/// # TctiNameConf::from_environment_variable().expect("Failed to get TCTI"),
@@ -117,6 +119,7 @@ impl Context {
117119
/// },
118120
/// )
119121
/// .expect("Failed to certify object handle");
122+
/// # }
120123
/// ```
121124
pub fn certify(
122125
&mut self,
@@ -204,6 +207,8 @@ impl Context {
204207
/// structures::{Data, SignatureScheme},
205208
/// interface_types::session_handles::AuthSession,
206209
/// };
210+
/// # #[serial_test::file_serial]
211+
/// # fn main() {
207212
/// # let mut context =
208213
/// # Context::new(
209214
/// # TctiNameConf::from_environment_variable().expect("Failed to get TCTI"),
@@ -238,6 +243,7 @@ impl Context {
238243
/// },
239244
/// )
240245
/// .expect("Failed to certify creation");
246+
/// # }
241247
/// ```
242248
pub fn certify_creation(
243249
&mut self,
@@ -318,6 +324,8 @@ impl Context {
318324
/// },
319325
/// };
320326
///
327+
/// # #[serial_test::file_serial]
328+
/// # fn main() {
321329
/// # let mut context =
322330
/// # Context::new(
323331
/// # TctiNameConf::from_environment_variable().expect("Failed to get TCTI"),
@@ -385,6 +393,7 @@ impl Context {
385393
/// # panic!("Attested did not contain the expected variant.")
386394
/// # }
387395
/// # }
396+
/// # }
388397
/// ```
389398
pub fn quote(
390399
&mut self,
@@ -465,6 +474,8 @@ impl Context {
465474
/// structures::{Data, SignatureScheme},
466475
/// interface_types::session_handles::AuthSession,
467476
/// };
477+
/// # #[serial_test::file_serial]
478+
/// # fn main() {
468479
/// # let mut context =
469480
/// # Context::new(
470481
/// # TctiNameConf::from_environment_variable().expect("Failed to get TCTI"),
@@ -499,6 +510,7 @@ impl Context {
499510
/// },
500511
/// )
501512
/// .expect("Failed to get tpm time");
513+
/// # }
502514
/// ```
503515
pub fn get_time(
504516
&mut self,

tss-esapi/src/context/tpm_commands/capability_commands.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ impl Context {
2828
///
2929
/// ```rust
3030
/// # use tss_esapi::{Context, TctiNameConf};
31+
/// # #[serial_test::file_serial]
32+
/// # fn main() {
3133
/// # // Create context
3234
/// # let mut context =
3335
/// # Context::new(
@@ -39,6 +41,7 @@ impl Context {
3941
/// let (_capabilities, _more) = context
4042
/// .get_capability(CapabilityType::Algorithms, 0, 80)
4143
/// .expect("Failed to call get_capability");
44+
/// # }
4245
/// ```
4346
pub fn get_capability(
4447
&mut self,

tss-esapi/src/context/tpm_commands/context_management.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ impl Context {
7171
/// # };
7272
/// # use std::convert::TryFrom;
7373
/// # use std::str::FromStr;
74+
/// # #[serial_test::file_serial]
75+
/// # fn main() {
7476
/// # // Create context
7577
/// # let mut context =
7678
/// # Context::new(
@@ -126,6 +128,7 @@ impl Context {
126128
/// ctx.flush_context(key_handle.into()).expect("Call to flush_context failed");
127129
/// assert!(ctx.read_public(key_handle).is_err());
128130
/// })
131+
/// # }
129132
/// ```
130133
pub fn flush_context(&mut self, handle: ObjectHandle) -> Result<()> {
131134
ReturnCode::ensure_success(
@@ -183,6 +186,8 @@ impl Context {
183186
/// # tss2_esys::TPM2_HANDLE,
184187
/// # };
185188
/// # use std::{env, str::FromStr, convert::TryFrom};
189+
/// # #[serial_test::file_serial]
190+
/// # fn main() {
186191
/// # // Create context
187192
/// # let mut context =
188193
/// # Context::new(
@@ -281,6 +286,7 @@ impl Context {
281286
/// # .expect("Failed to evict persistent handle")
282287
/// # });
283288
/// # assert_ne!(retireved_persistent_handle, ObjectHandle::None);
289+
/// # }
284290
/// ```
285291
///
286292
/// Make persistent object transient
@@ -302,6 +308,8 @@ impl Context {
302308
/// # tss2_esys::TPM2_HANDLE,
303309
/// # };
304310
/// # use std::{env, str::FromStr, convert::TryFrom};
311+
/// # #[serial_test::file_serial]
312+
/// # fn main() {
305313
/// # // Create context
306314
/// # let mut context =
307315
/// # Context::new(
@@ -401,6 +409,7 @@ impl Context {
401409
/// .expect("Failed to evict persistent handle")
402410
/// });
403411
/// # assert_ne!(retrieved_persistent_handle, ObjectHandle::None);
412+
/// # }
404413
/// ```
405414
pub fn evict_control(
406415
&mut self,

0 commit comments

Comments
 (0)