Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit da7409da authored by Mark Salyzyn's avatar Mark Salyzyn Committed by Gerrit Code Review
Browse files

Merge "logd: enable UID spam filter and test"

parents 1ab0cf4d e821dace
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ void Prune::format(char **strp) {
}

PruneList::PruneList()
        : mWorstUidEnabled(false) {
        : mWorstUidEnabled(true) {
    mNaughty.clear();
    mNice.clear();
}
+51 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <gtest/gtest.h>

#include "cutils/sockets.h"
#include "log/log.h"
#include "log/logger.h"

#define __unused __attribute__((__unused__))
@@ -96,8 +97,9 @@ static char *find_benchmark_spam(char *cp)
    //
    // main: UID/PID Total size/num   Now          UID/PID[?]  Total
    // 0           7500306/304207     71608/3183   0/4225?     7454388/303656
    //    <wrap>                                                     93432/1012
    // -or-
    // 0/gone      7454388/303656
    // 0/gone      7454388/303656     93432/1012
    //
    // basically if we see a *large* number of 0/????? entries
    unsigned long value;
@@ -126,6 +128,15 @@ static char *find_benchmark_spam(char *cp)
                value = value * 10ULL + *cp - '0';
                ++cp;
            }
            if (*cp != '/') {
                value = 0;
                continue;
            }
            while (isdigit(*++cp));
            while (*cp == ' ') ++cp;
            if (!isdigit(*cp)) {
                value = 0;
            }
        }
    } while ((value < 900000ULL) && *cp);
    return cp;
@@ -624,7 +635,45 @@ TEST(logd, benchmark) {
#endif

    ASSERT_TRUE(NULL != buf);
    EXPECT_TRUE(find_benchmark_spam(buf) != NULL);

    char *benchmark_statistics_found = find_benchmark_spam(buf);
    ASSERT_TRUE(benchmark_statistics_found != NULL);

    // Check how effective the SPAM filter is, parse out Now size.
    //             Total               Now
    // 0/4225?     7454388/303656      31488/755
    //                                 ^-- benchmark_statistics_found

    unsigned long nowSize = atol(benchmark_statistics_found);

    delete [] buf;

    ASSERT_NE(0UL, nowSize);

    int sock = socket_local_client("logd",
                                   ANDROID_SOCKET_NAMESPACE_RESERVED,
                                   SOCK_STREAM);
    static const unsigned long expected_absolute_minimum_log_size = 65536UL;
    unsigned long totalSize = expected_absolute_minimum_log_size;
    if (sock >= 0) {
        static const char getSize[] = {
            'g', 'e', 't', 'L', 'o', 'g', 'S', 'i', 'z', 'e', ' ',
            LOG_ID_MAIN + '0', '\0'
        };
        if (write(sock, getSize, sizeof(getSize)) > 0) {
            char buffer[80];
            memset(buffer, 0, sizeof(buffer));
            read(sock, buffer, sizeof(buffer));
            totalSize = atol(buffer);
            if (totalSize < expected_absolute_minimum_log_size) {
                totalSize = expected_absolute_minimum_log_size;
            }
        }
        close(sock);
    }
    // logd allows excursions to 110% of total size
    totalSize = (totalSize * 11 ) / 10;

    // 50% threshold for SPAM filter (<20% typical, lots of engineering margin)
    ASSERT_GT(totalSize, nowSize * 2);
}