• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef NO_PSTORE
25   FILE* fp;
26   ASSERT_TRUE(NULL != (fp = fopen("/dev/pmsg0", "ae")));
27   static const char message[] = "libc.__pstore_append\n";
28   ASSERT_EQ((size_t)1, fwrite(message, sizeof(message), 1, fp));
29   int fflushReturn = fflush(fp);
30   int fflushErrno = fflushReturn ? errno : 0;
31   ASSERT_EQ(0, fflushReturn);
32   ASSERT_EQ(0, fflushErrno);
33   int fcloseReturn = fclose(fp);
34   int fcloseErrno = fcloseReturn ? errno : 0;
35   ASSERT_EQ(0, fcloseReturn);
36   ASSERT_EQ(0, fcloseErrno);
37   if ((fcloseErrno == ENOMEM) || (fflushErrno == ENOMEM)) {
38     fprintf(stderr,
39             "Kernel does not have space allocated to pmsg pstore driver "
40             "configured\n");
41   }
42   if (!fcloseReturn && !fcloseErrno && !fflushReturn && !fflushReturn) {
43     fprintf(stderr,
44             "Reboot, ensure string libc.__pstore_append is in "
45             "/sys/fs/pstore/pmsg-ramoops-0\n");
46   }
47 #else  /* NO_PSTORE */
48   GTEST_LOG_(INFO) << "This test does nothing because of NO_PSTORE.\n";
49 #endif /* NO_PSTORE */
50 #else
51   GTEST_LOG_(INFO) << "This test does nothing.\n";
52 #endif
53 }
54