Home | History | Annotate | Download | only in tests
      1 /*
      2  * Copyright (C) 2015 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 <errno.h>
     18 #include <stdarg.h>
     19 
     20 #include <string>
     21 
     22 #include <android-base/stringprintf.h>
     23 #include <log/log.h>
     24 #include <log/logger.h>
     25 
     26 // Forward declarations.
     27 class Backtrace;
     28 struct EventTagMap;
     29 struct AndroidLogEntry;
     30 
     31 std::string g_fake_log_buf;
     32 
     33 std::string g_fake_log_print;
     34 
     35 void resetLogs() {
     36   g_fake_log_buf = "";
     37   g_fake_log_print = "";
     38 }
     39 
     40 std::string getFakeLogBuf() {
     41   return g_fake_log_buf;
     42 }
     43 
     44 std::string getFakeLogPrint() {
     45   return g_fake_log_print;
     46 }
     47 
     48 extern "C" int __libc_format_log(int priority, const char* tag, const char* format, ...) {
     49   g_fake_log_print += std::to_string(priority) + ' ';
     50   g_fake_log_print += tag;
     51   g_fake_log_print += ' ';
     52 
     53   va_list ap;
     54   va_start(ap, format);
     55   android::base::StringAppendV(&g_fake_log_print, format, ap);
     56   va_end(ap);
     57 
     58   g_fake_log_print += '\n';
     59 
     60   return 0;
     61 }
     62 
     63 extern "C" int __android_log_buf_write(int bufId, int prio, const char* tag, const char* msg) {
     64   g_fake_log_buf += std::to_string(bufId) + ' ' + std::to_string(prio) + ' ';
     65   g_fake_log_buf += tag;
     66   g_fake_log_buf += ' ';
     67   g_fake_log_buf += msg;
     68   return 1;
     69 }
     70 
     71 extern "C" int __android_log_print(int prio, const char* tag, const char* fmt, ...) {
     72   g_fake_log_print += std::to_string(prio) + ' ';
     73   g_fake_log_print += tag;
     74   g_fake_log_print += ' ';
     75 
     76   va_list ap;
     77   va_start(ap, fmt);
     78   android::base::StringAppendV(&g_fake_log_print, fmt, ap);
     79   va_end(ap);
     80 
     81   g_fake_log_print += '\n';
     82 
     83   return 1;
     84 }
     85 
     86 extern "C" log_id_t android_name_to_log_id(const char*) {
     87   return LOG_ID_SYSTEM;
     88 }
     89 
     90 extern "C" struct logger_list* android_logger_list_open(log_id_t, int, unsigned int, pid_t) {
     91   errno = EACCES;
     92   return nullptr;
     93 }
     94 
     95 extern "C" int android_logger_list_read(struct logger_list*, struct log_msg*) {
     96   return 0;
     97 }
     98 
     99 extern "C" EventTagMap* android_openEventTagMap(const char*) {
    100   return nullptr;
    101 }
    102 
    103 extern "C" int android_log_processBinaryLogBuffer(
    104     struct logger_entry*,
    105     AndroidLogEntry*, const EventTagMap*, char*, int) {
    106   return 0;
    107 }
    108 
    109 extern "C" void android_logger_list_free(struct logger_list*) {
    110 }
    111