1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://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, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #include <gtest/gtest.h> 16 #include <unistd.h> 17 18 #include "gwpasan_collector.h" 19 20 using namespace testing::ext; 21 namespace OHOS { 22 namespace HiviewDFX { 23 class AsanUnittest : public testing::Test { 24 public: SetUp()25 void SetUp() 26 { 27 chmod("/data/log/faultlog/", 0777); // 0777: add other user write permission 28 chmod("/data/log/faultlog/faultlogger/", 0777); // 0777: add other user write permission 29 sleep(1); 30 }; TearDown()31 void TearDown() 32 { 33 chmod("/data/log/faultlog/", 0770); // 0770: restore permission 34 chmod("/data/log/faultlog/faultlogger/", 0770); // 0770: restore permission 35 }; 36 }; 37 38 /** 39 * @tc.name: AsanTest001 40 * @tc.desc: Test calling WriteGwpAsanLog Func 41 * @tc.type: FUNC 42 */ 43 HWTEST_F(AsanUnittest, WriteGwpAsanLogTest001, testing::ext::TestSize.Level1) 44 { 45 char gwpAsanBuf[] = "Test GWP-ASAN, End GWP-ASan report"; 46 WriteGwpAsanLog(gwpAsanBuf, strlen(gwpAsanBuf)); 47 char cfiBuf[] = "Test CFI, End CFI report"; 48 WriteGwpAsanLog(cfiBuf, strlen(cfiBuf)); 49 char ubsanBuf[] = "Test UBSAN, End Ubsan report"; 50 WriteGwpAsanLog(ubsanBuf, strlen(ubsanBuf)); 51 char tsanBuf[] = "Test TSAN, End Tsan report"; 52 WriteGwpAsanLog(tsanBuf, strlen(tsanBuf)); 53 char hwasanBuf[] = "Test HWASAN, End Hwasan report"; 54 WriteGwpAsanLog(hwasanBuf, strlen(hwasanBuf)); 55 char asanBuf[] = "Test ASAN, End Asan report"; 56 WriteGwpAsanLog(asanBuf, strlen(asanBuf)); 57 ASSERT_TRUE(true); 58 } 59 } // namespace HiviewDFX 60 } // namespace OHOS 61