1 /*
2  * Copyright (C) 2014 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 #include <gtest/gtest.h>
18 
19 #include <errno.h>
20 #include <stdio.h>
21 
TEST(libc,__pstore_append)22 TEST(libc, __pstore_append) {
23 #ifdef __ANDROID__
24   FILE* fp;
25   ASSERT_TRUE(NULL != (fp = fopen("/dev/pmsg0", "a")));
26   static const char message[] = "libc.__pstore_append\n";
27   ASSERT_EQ((size_t)1, fwrite(message, sizeof(message), 1, fp));
28   int fflushReturn = fflush(fp);
29   int fflushErrno = fflushReturn ? errno : 0;
30   ASSERT_EQ(0, fflushReturn);
31   ASSERT_EQ(0, fflushErrno);
32   int fcloseReturn = fclose(fp);
33   int fcloseErrno = fcloseReturn ? errno : 0;
34   ASSERT_EQ(0, fcloseReturn);
35   ASSERT_EQ(0, fcloseErrno);
36   if ((fcloseErrno == ENOMEM) || (fflushErrno == ENOMEM)) {
37     fprintf(stderr,
38             "Kernel does not have space allocated to pmsg pstore driver "
39             "configured\n");
40   }
41   if (!fcloseReturn && !fcloseErrno && !fflushReturn && !fflushReturn) {
42     fprintf(stderr,
43             "Reboot, ensure string libc.__pstore_append is in "
44             "/sys/fs/pstore/pmsg-ramoops-0\n");
45   }
46 #else
47   GTEST_LOG_(INFO) << "This test does nothing.\n";
48 #endif
49 }
50