1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 use core::sync::atomic::{AtomicBool, Ordering}; 18 19 pub static CONTEXT: TestContext = TestContext::new(); 20 21 #[derive(Debug, Default)] 22 pub struct TestContext { 23 all_ok: AtomicBool, 24 hard_fail: AtomicBool, 25 skipped: AtomicBool, 26 } 27 28 impl TestContext { new() -> Self29 const fn new() -> Self { 30 Self { 31 all_ok: AtomicBool::new(true), 32 hard_fail: AtomicBool::new(false), 33 skipped: AtomicBool::new(false), 34 } 35 } 36 fail(&self, hard_fail: bool)37 pub fn fail(&self, hard_fail: bool) { 38 self.all_ok.store(false, Ordering::Relaxed); 39 self.hard_fail.fetch_or(hard_fail, Ordering::Relaxed); 40 } 41 skip(&self)42 pub fn skip(&self) { 43 self.skipped.store(true, Ordering::Relaxed); 44 } 45 reset(&self)46 pub(crate) fn reset(&self) { 47 self.all_ok.store(true, Ordering::Relaxed); 48 self.hard_fail.store(false, Ordering::Relaxed); 49 self.skipped.store(false, Ordering::Relaxed); 50 } 51 skipped(&self) -> bool52 pub(crate) fn skipped(&self) -> bool { 53 self.skipped.load(Ordering::Relaxed) 54 } 55 all_ok(&self) -> bool56 pub(crate) fn all_ok(&self) -> bool { 57 self.all_ok.load(Ordering::Relaxed) 58 } 59 hard_fail(&self) -> bool60 pub(crate) fn hard_fail(&self) -> bool { 61 self.hard_fail.load(Ordering::Relaxed) 62 } 63 } 64