Skip to content

Commit 1b3590e

Browse files
authored
test: Replace feature requirements with component ones (#72)
add headers fill record_properties for each test
1 parent de5d94a commit 1b3590e

File tree

5 files changed

+262
-42
lines changed

5 files changed

+262
-42
lines changed

src/rust/rust_kvs/tests/cit_default_values.rs

Lines changed: 105 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
//! Persistency tests.
2-
//!
3-
//! Requirements verified:
4-
//! - Default Values (feat_req__persistency__default_values)
5-
//! The KVS system shall support predefined default values for keys.
6-
//! - Default Values Retrieval (feat_req__persistency__default_value_get)
7-
//! The KVS system shall support retrieving the default value associated with a key.
8-
//! - Set default key values via file (feat_req__persistency__default_value_file)
9-
//! The KVS shall support the configuration of default key values using an external file.
10-
//!
1+
// Copyright (c) 2025 Contributors to the Eclipse Foundation
2+
//
3+
// See the NOTICE file(s) distributed with this work for additional
4+
// information regarding copyright ownership.
5+
//
6+
// This program and the accompanying materials are made available under the
7+
// terms of the Apache License Version 2.0 which is available at
8+
// <https://www.apache.org/licenses/LICENSE-2.0>
9+
//
10+
// SPDX-License-Identifier: Apache-2.0
11+
1112
use rust_kvs::prelude::*;
1213
use std::collections::HashMap;
1314
use std::path::Path;
@@ -48,6 +49,11 @@ fn write_defaults_file(
4849
}
4950

5051
#[test]
52+
// #[record_property("PartiallyVerifies", ["comp_req__persistency__value_default", "comp_req__persistency__default_value_config", "comp_req__persistency__default_value_types", "comp_req__persistency__default_value_query"])]
53+
// #[record_property("FullyVerifies", [])]
54+
// #[record_property("Description", "Verifies default value loading, querying, and override behavior for KVS instances with and without defaults.")]
55+
// #[record_property("TestType", "requirements-based")]
56+
// #[record_property("DerivationTechnique", "requirements-based")]
5157
fn cit_persistency_default_values() -> Result<(), ErrorCode> {
5258
// Temp directory.
5359
let dir = tempdir()?;
@@ -88,11 +94,23 @@ fn cit_persistency_default_values() -> Result<(), ErrorCode> {
8894
kvs_with_defaults.is_value_default(&keyname)?,
8995
"kvs_with_defaults: key '{keyname}' should be default"
9096
);
97+
assert_eq!(
98+
kvs_with_defaults.get_default_value(&keyname)?,
99+
KvsValue::from(default_value),
100+
"kvs_with_defaults: key '{keyname}' should have default value {default_value}"
101+
);
91102
assert_eq!(
92103
kvs_without_defaults.is_value_default(&keyname).unwrap_err(),
93104
ErrorCode::KeyNotFound,
94105
"kvs_without_defaults: key '{keyname}' should not exist and return KeyNotFound"
95106
);
107+
assert_eq!(
108+
kvs_without_defaults
109+
.get_default_value(&keyname)
110+
.unwrap_err(),
111+
ErrorCode::KeyNotFound,
112+
"kvs_without_defaults: key '{keyname}' should not exist and return KeyNotFound"
113+
);
96114

97115
// Check values.
98116
assert_eq!(
@@ -153,6 +171,11 @@ fn cit_persistency_default_values() -> Result<(), ErrorCode> {
153171
}
154172

155173
#[test]
174+
// #[record_property("PartiallyVerifies", ["comp_req__persistency__value_default", "comp_req__persistency__default_value_config", "comp_req__persistency__default_value_types"])]
175+
// #[record_property("FullyVerifies", [""])]
176+
// #[record_property("Description", "Checks that KVS loads default values when defaults are present and OpenNeedDefaults is set to Optional.")]
177+
// #[record_property("TestType", "requirements-based")]
178+
// #[record_property("DerivationTechnique", "requirements-based")]
156179
fn cit_persistency_default_values_optional() -> Result<(), ErrorCode> {
157180
// Temp directory.
158181
let dir = tempdir().unwrap();
@@ -198,6 +221,11 @@ fn cit_persistency_default_values_optional() -> Result<(), ErrorCode> {
198221
}
199222

200223
#[test]
224+
// #[record_property("PartiallyVerifies", ["comp_req__persistency__value_default", "comp_req__persistency__default_value_config", "comp_req__persistency__default_value_types"])]
225+
// #[record_property("FullyVerifies", [""])]
226+
// #[record_property("Description", "Tests removal of values in KVS with defaults enabled, ensuring keys revert to their default values.")]
227+
// #[record_property("TestType", "requirements-based")]
228+
// #[record_property("DerivationTechnique", "requirements-based")]
201229
fn cit_persistency_defaults_enabled_values_removal() -> Result<(), ErrorCode> {
202230
// Temp directory.
203231
let dir = tempdir()?;
@@ -257,6 +285,11 @@ fn cit_persistency_defaults_enabled_values_removal() -> Result<(), ErrorCode> {
257285
}
258286

259287
#[test]
288+
// #[record_property("PartiallyVerifies", ["comp_req__persistency__value_default", "comp_req__persistency__default_value_types"])]
289+
// #[record_property("FullyVerifies", [""])]
290+
// #[record_property("Description", "Tests removal of values in KVS without defaults, ensuring removed keys are not found and return KeyNotFound.")]
291+
// #[record_property("TestType", "requirements-based")]
292+
// #[record_property("DerivationTechnique", "requirements-based")]
260293
fn cit_persistency_defaults_disabled_values_removal() -> Result<(), ErrorCode> {
261294
// Temp directory.
262295
let dir = tempdir()?;
@@ -296,6 +329,11 @@ fn cit_persistency_defaults_disabled_values_removal() -> Result<(), ErrorCode> {
296329
}
297330

298331
#[test]
332+
// #[record_property("PartiallyVerifies", ["comp_req__persistency__value_default", "comp_req__persistency__default_value_config", "comp_req__persistency__default_value_types"])]
333+
// #[record_property("FullyVerifies", [""])]
334+
// #[record_property("Description", "Verifies that KVS fails to open when the defaults file contains invalid JSON.")]
335+
// #[record_property("TestType", "requirements-based")]
336+
// #[record_property("DerivationTechnique", "requirements-based")]
299337
fn cit_persistency_invalid_default_values() -> Result<(), ErrorCode> {
300338
// Temp directory.
301339
let dir = tempdir()?;
@@ -324,6 +362,11 @@ fn cit_persistency_invalid_default_values() -> Result<(), ErrorCode> {
324362
}
325363

326364
#[test]
365+
// #[record_property("PartiallyVerifies", ["comp_req__persistency__value_default", "comp_req__persistency__default_value_config", "comp_req__persistency__default_value_types"])]
366+
// #[record_property("FullyVerifies", ["comp_req__persistency__value_reset"])]
367+
// #[record_property("Description", "Checks that resetting KVS restores all keys to their default values.")]
368+
// #[record_property("TestType", "requirements-based")]
369+
// #[record_property("DerivationTechnique", "requirements-based")]
327370
fn cit_persistency_reset_all_default_values() -> Result<(), ErrorCode> {
328371
// Temp directory.
329372
let dir = tempdir()?;
@@ -396,7 +439,58 @@ fn cit_persistency_reset_all_default_values() -> Result<(), ErrorCode> {
396439
}
397440

398441
#[test]
399-
#[ignore]
442+
// #[record_property("PartiallyVerifies", ["comp_req__persistency__value_default", "comp_req__persistency__default_value_config"])]
443+
// #[record_property("FullyVerifies", ["comp_req__persistency__default_value_checksum"])]
444+
// #[record_property("Description", "Ensures that a checksum file is created when opening KVS with defaults.")]
445+
// #[record_property("TestType", "requirements-based")]
446+
// #[record_property("DerivationTechnique", "requirements-based")]
447+
fn cit_persistency_defaults_checksum() -> Result<(), ErrorCode> {
448+
// Temp directory.
449+
let dir = tempdir()?;
450+
let dir_string = dir.path().to_string_lossy().to_string();
451+
452+
// Values.
453+
let keyname = "test_number".to_string();
454+
let default_value = 111.1;
455+
// Create defaults file for instance 0.
456+
let default_id = InstanceId(0);
457+
write_defaults_file(
458+
dir.path(),
459+
HashMap::from([(keyname.clone(), JsonValue::from(default_value))]),
460+
default_id,
461+
)?;
462+
463+
let hash_file = dir.path().join(format!("kvs_{default_id}_0.hash"));
464+
assert!(
465+
!hash_file.exists(),
466+
"Hash file should NOT exist before opening KVS with defaults"
467+
);
468+
469+
{
470+
// KVS instance with defaults.
471+
let kvs_with_defaults = Kvs::open(
472+
default_id.clone(),
473+
OpenNeedDefaults::Required,
474+
OpenNeedKvs::Optional,
475+
Some(dir_string.clone()),
476+
)?;
477+
}
478+
479+
assert!(
480+
hash_file.exists(),
481+
"Hash file should exist after opening KVS with defaults"
482+
);
483+
484+
Ok(())
485+
}
486+
487+
#[test]
488+
// #[record_property("PartiallyVerifies", ["comp_req__persistency__value_default", "comp_req__persistency__default_value_config"])]
489+
// #[record_property("FullyVerifies", [""])]
490+
// #[record_property("Description", "Placeholder for future test: should verify resetting a single key to its default value.")]
491+
// #[record_property("TestType", "requirements-based")]
492+
// #[record_property("DerivationTechnique", "requirements-based")]
493+
#[ignore = "not implemented yet"]
400494
fn cit_persistency_reset_single_default_value() -> Result<(), ErrorCode> {
401495
// TODO: This test is not implemented yet.
402496
// API supports resetting only all keys.

src/rust/rust_kvs/tests/cit_multiple_kvs.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
//! Persistency tests.
2-
//!
3-
//! Requirements verified:
4-
//! - Multiple KVS per Software Architecture Element (feat_req__persistency__multiple_kvs)
5-
//! The KVS system shall allow instantiating multiple independent stores per software architecture element.
6-
//! - Intra-Process Data Access (feat_req__persistency__intra_process_comm)
7-
//! The KVS shall support concurrent intra-process data access.
8-
//!
1+
// Copyright (c) 2025 Contributors to the Eclipse Foundation
2+
//
3+
// See the NOTICE file(s) distributed with this work for additional
4+
// information regarding copyright ownership.
5+
//
6+
// This program and the accompanying materials are made available under the
7+
// terms of the Apache License Version 2.0 which is available at
8+
// <https://www.apache.org/licenses/LICENSE-2.0>
9+
//
10+
// SPDX-License-Identifier: Apache-2.0
11+
912
use rust_kvs::prelude::*;
1013
use tempfile::tempdir;
1114

1215
#[test]
16+
// #[record_property("PartiallyVerifies", ["comp_req__persistency__multi_instance", "comp_req__persistency__concurrency"])]
17+
// #[record_property("FullyVerifies", [""])]
18+
// #[record_property("Description", "Verifies that multiple KVS instances with different IDs store and retrieve independent values without interference.")]
19+
// #[record_property("TestType", "requirements-based")]
20+
// #[record_property("DerivationTechnique", "requirements-based")]
1321
fn cit_persistency_multiple_instances() -> Result<(), ErrorCode> {
1422
// Temp directory.
1523
let dir = tempdir()?;
@@ -85,6 +93,11 @@ fn cit_persistency_multiple_instances() -> Result<(), ErrorCode> {
8593
}
8694

8795
#[test]
96+
// #[record_property("PartiallyVerifies", ["comp_req__persistency__multi_instance", "comp_req__persistency__concurrency"])]
97+
// #[record_property("FullyVerifies", [""])]
98+
// #[record_property("Description", "Checks that multiple KVS instances with the same ID and key maintain consistent values across instances.")]
99+
// #[record_property("TestType", "requirements-based")]
100+
// #[record_property("DerivationTechnique", "requirements-based")]
88101
fn cit_persistency_multiple_instances_same_id_common_value() -> Result<(), ErrorCode> {
89102
// Temp directory.
90103
let dir = tempdir()?;
@@ -148,7 +161,12 @@ fn cit_persistency_multiple_instances_same_id_common_value() -> Result<(), Error
148161
}
149162

150163
#[test]
151-
#[ignore]
164+
// #[record_property("PartiallyVerifies", ["comp_req__persistency__multi_instance", "comp_req__persistency__concurrency"])]
165+
// #[record_property("FullyVerifies", [""])]
166+
// #[record_property("Description", "Verifies that changes in one KVS instance with a shared ID and key are reflected in another instance, demonstrating interference.")]
167+
// #[record_property("TestType", "requirements-based")]
168+
// #[record_property("DerivationTechnique", "requirements-based")]
169+
#[ignore = "https://github.com/qorix-group/inc_mw_per/issues/20"]
152170
fn cit_persistency_multiple_instances_same_id_interfere() -> Result<(), ErrorCode> {
153171
// TODO: https://github.com/qorix-group/inc_mw_per/issues/20
154172

src/rust/rust_kvs/tests/cit_persistency.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
//! Persistency tests.
2-
//!
3-
//! Requirements verified:
4-
//! - Persistency (feat_req__persistency__persistency)
5-
//! The KVS system shall persist stored data and provide an API to explicitly trigger persistence.
6-
//! - Store persistent data (feat_req__persistency__persist_data)
7-
//! The KVS shall support storing and loading its data to and from persistent storage.
1+
// Copyright (c) 2025 Contributors to the Eclipse Foundation
2+
//
3+
// See the NOTICE file(s) distributed with this work for additional
4+
// information regarding copyright ownership.
5+
//
6+
// This program and the accompanying materials are made available under the
7+
// terms of the Apache License Version 2.0 which is available at
8+
// <https://www.apache.org/licenses/LICENSE-2.0>
9+
//
10+
// SPDX-License-Identifier: Apache-2.0
811

912
mod common;
1013
use common::compare_kvs_values;
@@ -15,6 +18,11 @@ use tempfile::tempdir;
1518
/// Flush on exit is enabled by default.
1619
/// Data will be flushed on `kvs` being dropped.
1720
#[test]
21+
// #[record_property("PartiallyVerifies", [])]
22+
// #[record_property("FullyVerifies", ["comp_req__persistency__persist_data_store_com"])]
23+
// #[record_property("Description", "Verifies that data is automatically flushed and persisted when the KVS instance is dropped, with flush on exit enabled.")]
24+
// #[record_property("TestType", "requirements-based")]
25+
// #[record_property("DerivationTechnique", "requirements-based")]
1826
fn cit_persistency_flush_on_exit_enabled() -> Result<(), ErrorCode> {
1927
// Temp directory.
2028
let dir = tempdir()?;
@@ -75,6 +83,11 @@ fn cit_persistency_flush_on_exit_enabled() -> Result<(), ErrorCode> {
7583
}
7684

7785
#[test]
86+
// #[record_property("PartiallyVerifies", [])]
87+
// #[record_property("FullyVerifies", ["comp_req__persistency__persist_data_store_com"])]
88+
// #[record_property("Description", "Checks that disabling flush on exit causes data to be dropped and not persisted after the KVS instance is dropped.")]
89+
// #[record_property("TestType", "requirements-based")]
90+
// #[record_property("DerivationTechnique", "requirements-based")]
7891
fn cit_persistency_flush_on_exit_disabled_drop_data() -> Result<(), ErrorCode> {
7992
// Temp directory.
8093
let dir = tempdir()?;
@@ -133,6 +146,11 @@ fn cit_persistency_flush_on_exit_disabled_drop_data() -> Result<(), ErrorCode> {
133146
}
134147

135148
#[test]
149+
// #[record_property("PartiallyVerifies", [])]
150+
// #[record_property("FullyVerifies", ["comp_req__persistency__persist_data_store_com"])]
151+
// #[record_property("Description", "Verifies that disabling flush on exit but manually flushing ensures data is persisted correctly.")]
152+
// #[record_property("TestType", "requirements-based")]
153+
// #[record_property("DerivationTechnique", "requirements-based")]
136154
fn cit_persistency_flush_on_exit_disabled_manual_flush() -> Result<(), ErrorCode> {
137155
// Temp directory.
138156
let dir = tempdir()?;

0 commit comments

Comments
 (0)