• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2025 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 #![no_std]
15 #![no_main]
16 
17 use regs::ops;
18 use unittest::test;
19 
20 #[test]
mask_calculated_correctly() -> unittest::Result<()>21 fn mask_calculated_correctly() -> unittest::Result<()> {
22     unittest::assert_eq!(ops::mask(8, 15), 0x0000_ff00);
23     Ok(())
24 }
25 
26 #[test]
get_bool_extracts_correct_value() -> unittest::Result<()>27 fn get_bool_extracts_correct_value() -> unittest::Result<()> {
28     unittest::assert_false!(ops::get_bool(0x0000_0100, 7));
29     unittest::assert_true!(ops::get_bool(0x0000_0100, 8));
30     unittest::assert_false!(ops::get_bool(0x0000_0100, 9));
31     Ok(())
32 }
33 
34 #[test]
set_bool_preserved_unmasked_value() -> unittest::Result<()>35 fn set_bool_preserved_unmasked_value() -> unittest::Result<()> {
36     unittest::assert_eq!(ops::set_bool(0xffff_ffff, 16, false), 0xfffe_ffff);
37     Ok(())
38 }
39 
40 #[test]
get_u32_extracts_correct_value() -> unittest::Result<()>41 fn get_u32_extracts_correct_value() -> unittest::Result<()> {
42     unittest::assert_eq!(ops::get_u32(0x5555_aa55, 8, 15), 0xaa);
43     Ok(())
44 }
45 
46 #[test]
set_u32_preserves_unmasked_value() -> unittest::Result<()>47 fn set_u32_preserves_unmasked_value() -> unittest::Result<()> {
48     unittest::assert_eq!(ops::set_u32(0x5555_5555, 8, 15, 0xaa), 0x5555_aa55);
49     Ok(())
50 }
51 
52 #[test]
single_bit_get_u32_extracts_correct_value() -> unittest::Result<()>53 fn single_bit_get_u32_extracts_correct_value() -> unittest::Result<()> {
54     unittest::assert_eq!(ops::get_u32(0x0001_0000, 16, 16), 0b1);
55     Ok(())
56 }
57 
58 #[test]
single_bit_set_u32_sets_correct_value() -> unittest::Result<()>59 fn single_bit_set_u32_sets_correct_value() -> unittest::Result<()> {
60     unittest::assert_eq!(ops::set_u32(0xffff_ffff, 16, 16, 0b0), 0xfffe_ffff);
61     Ok(())
62 }
63