blob: 8a5f2626b58dadc76f2f0f659b161b85bf9f2cc1 [file] [log] [blame]
Brian Silvermane4c79ce2022-08-15 05:57:28 -07001use std::{ffi::CString, sync::Once};
2
3autocxx::include_cpp! (
4#include "aos/init.h"
5
6safety!(unsafe)
7
8generate!("aos::InitFromRust")
9);
10
11/// Initializes things for a test.
12///
13/// TODO(Brian): Should we provide a proc macro attribute that handles calling this?
14///
15/// # Panics
16///
17/// Panics if non-test initialization has already been performed.
18pub fn test_init() {
19 static ONCE: Once = Once::new();
20 ONCE.call_once(|| {
21 let argv0 = std::env::args().next().expect("must have argv[0]");
22 let argv0 = CString::new(argv0).expect("argv[0] may not have NUL");
23 // SAFETY: argv0 is a NUL-terminated string.
24 unsafe { ffi::aos::InitFromRust(argv0.as_ptr()) };
25 });
26
27 // TODO(Brian): Do we want any of the other stuff that `:gtest_main` has?
28 // TODO(Brian): Call `aos::SetShmBase` like `:gtest_main` does.
29}