Commit graph

485 commits

Author SHA1 Message Date
Mark Salyzyn
067e8a0725 liblog: test: CTS: enoent does not qualify
Eliminate liblog@enoent CTS test as it is bypassed on "user" builds
in commit "liblog: test: enoent requires userdebug or eng to run".
This prevents time wasted running a test that bypasses during CTS.

Test: CtsLiblogTestCases_list --gtest_list_tests |
      (grep enoent && echo FAILED)
Bug: 62030441
Change-Id: Ia440db3e74dacdc5c311c640aab3a11844cc195a
2017-05-24 15:30:07 -07:00
Mark Salyzyn
558f2a166b liblog: test: android_logger_get_ "kernel" log buffer can be empty
(cherry picked from commit 37eaefa9a0)

If user build and for the "kernel" log buffer, allow an empty report.

Test: CTS: User: liblog#android_logger_get_
Test: remove ro.debuggable line from /default.prop,
      run liblog-unit-tests --gtest_filter=*.android_logger_get_
Bug: 62030309
Change-Id: I5f91af07608988f322b3c46574becc308e1d8b13
2017-05-24 12:50:38 -07:00
Mark Salyzyn
37eaefa9a0 liblog: test: android_logger_get_ "kernel" log buffer can be empty
If user build and for the "kernel" log buffer, allow an empty report.

Test: CTS: User: liblog#android_logger_get_
Test: remove ro.debuggable line from /default.prop,
      run liblog-unit-tests --gtest_filter=*.android_logger_get_
Bug: 62030309
Change-Id: I5f91af07608988f322b3c46574becc308e1d8b13
2017-05-24 12:45:41 -07:00
Mark Salyzyn
928e606d5a liblog: test: enoent requires userdebug or eng to run
(cherry picked from commit 38dad6c9e4)

Bypass test if we do not have all the prerequisites to run this check
of liblog failure propagation.  We need to be root, or be able to
call su, in order to temporarily stop logd to measure the error
response from liblog.  Basically a "user" build can not have the
levers to deny or fail the logger, preventing our ability to run the
liblog.enoent test.

Test: CTS: User: liblog#enoent
Test: remove ro.debuggable line from /default.prop,
      run liblog-unit-tests --gtest_filter=*.enoent
Bug: 62030441
Change-Id: I52177b8dd3c66d433bddf630e840ee088e13cddc
2017-05-24 09:15:27 -07:00
Mark Salyzyn
38dad6c9e4 liblog: test: enoent requires userdebug or eng to run
Bypass test if we do not have all the prerequisites to run this check
of liblog failure propagation.  We need to be root, or be able to
call su, in order to temporarily stop logd to measure the error
response from liblog.  Basically a "user" build can not have the
levers to deny or fail the logger, preventing our ability to run the
liblog.enoent test.

Test: CTS: User: liblog#enoent
Test: remove ro.debuggable line from /default.prop,
      run liblog-unit-tests --gtest_filter=*.enoent
Bug: 62030441
Change-Id: I52177b8dd3c66d433bddf630e840ee088e13cddc
2017-05-24 07:50:29 -07:00
Mark Salyzyn
f7690d9196 liblog: tests: crashes in logcat.descriptive
scanTagLine has some loops that do not check for a terminating nul,
problematic for responses from the logger via __getEventTag.

Test: gTest logcat-unit-tests --gtest_filter=*.descriptive
Bug: 37791296
Change-Id: Ib4e900b765b407bdee43e009d6625fe289863ddc
2017-05-12 13:07:08 -07:00
Dan Willemsen
f3452d8178 Remove old simulator support from liblog
As far as I know, this isn't used anymore, and is causing problems when
building with bionic on the host (with the cast of open).

Bug: 31559095
Test: host bionic compiles
Change-Id: I8b6e802e2d6dcc6e8476e387a5a365903aec3be1
2017-05-07 13:21:35 -07:00
Christopher Ferris
ac225780dd Move libc_logging to libasync_safe.
Move the name of the "private/libc_logging.h" header to <async_safe/log.h>.

For use of libc_malloc_debug_backtrace, remove the libc_logging library.
The library now includes the async safe log functions.

Remove the references to libc_logging.cpp in liblog, it isn't needed because
the code is already protected by a check of the __ANDROID__ define.

Test: Compiled and boot bullhead device.
Test: Run debuggerd unit tests.
Test: Run liblog unit tests on target and host.
Test: Run libmemunreachable unit tests (these tests are flaky though).
Change-Id: Ie79d7274febc31f210b610a2c4da958b5304e402
2017-05-02 18:38:46 -07:00
Steven Moreland
64328403b5 liblog: __android_log_error_write in vndk
Also added log_safetynet.h header. This contains a memory sensitive logging
function which is used to detect attack attempts.

Fixes: 37442967
Test: liblog-unit-tests on internal marlin
Test: build liblog with BOARD_VNDK_VERSION := current on aosp_arm
Test: libbinder vendor variant links with BOARD_VNDK_VERSION := current

Change-Id: Icfcc2b1acbb3712bf4c84403870dc93401eafb15
2017-05-01 14:40:55 +00:00
Mark Salyzyn
b7140c26d5 liblog: test: liblog.__security miscalculation
(cherry pick from commit b867beac56)

The gTest should not be able to set ro.device_owner, either as a unit
test or a CTS test.  The CTS test should not be able to set
persist.logd.security, the gTest may as it is run on userdebug with
root, so check if we are root to discern expectations.

Test: gTest liblog-unit-tests --gtest_filter=liblog.__security
Test: cts-tradefed run cts-dev -a armeabi-v7a -m CtsLiblogTestCases -t liblog#__security
Bug: 36480230
Change-Id: I1da88aae34da4e2fca8dd88d740eeb879d9c65bb
2017-04-21 08:20:56 -07:00
Mark Salyzyn
ad8d533a04 Merge changes Iec369a50,I78959464,I3f9f8d56 into oc-dev
* changes:
  logd: instrument tests better for failure
  logd: iterator corruption paranoia
  liblog: log_time add explicit to some constructors.
2017-04-20 20:44:28 +00:00
Mark Salyzyn
b867beac56 liblog: test: liblog.__security miscalculation
The gTest should not be able to set ro.device_owner, either as a unit
test or a CTS test.  The CTS test should not be able to set
persist.logd.security, the gTest may as it is run on userdebug with
root, so check if we are root to discern expectations.

Test: gTest liblog-unit-tests --gtest_filter=liblog.__security
Test: cts-tradefed run cts-dev -a armeabi-v7a -m CtsLiblogTestCases -t liblog#__security
Bug: 36480230
Change-Id: I1da88aae34da4e2fca8dd88d740eeb879d9c65bb
2017-04-20 13:26:12 -07:00
Mark Salyzyn
0dd92d5b92 liblog: log_time add usec() and msec()
Test: build
Bug: 37254265
Change-Id: Ie7a5303e85e565800f2066e53e19a83496acae72
2017-04-19 09:18:40 -07:00
Mark Salyzyn
86b136a4a4 liblog: __android_logger_property_bool svelte+eng default
(cherry pick from commit 9fcaaba85d)

When BOOL_DEFAULT_FLAG_ENG and/or BOOL_DEFAULT_FLAG_SVELTE is set for
flags parameter in __android_logger_property_get_bool, they can not be
overridden by a supplied property value.  Reset these two flags if
there is something in the specified property.

Test: gTest liblog-unit-tests, logcat-unit-tests and logd-unit-tests
Bug: 37425809
Change-Id: I5fc2d727e8c30bc1e781f8b365f44ec62dd36b4d
2017-04-19 08:24:31 -07:00
Mark Salyzyn
9fcaaba85d liblog: __android_logger_property_bool svelte+eng default
When BOOL_DEFAULT_FLAG_ENG and/or BOOL_DEFAULT_FLAG_SVELTE is set for
flags parameter in __android_logger_property_get_bool, they can not be
overridden by a supplied property value.  Reset these two flags if
there is something in the specified property.

Test: gTest liblog-unit-tests, logcat-unit-tests and logd-unit-tests
Bug: 37425809
Change-Id: I5fc2d727e8c30bc1e781f8b365f44ec62dd36b4d
2017-04-18 15:36:36 -07:00
Treehugger Robot
f358bed624 Merge "libcutils: compile with BOARD_VNDK_VERSION current" 2017-04-18 14:46:27 +00:00
Mark Salyzyn
219ef270a6 liblog: log_time add explicit to some constructors.
(cherry pick from commit d87d47f7dd)

Add explicit to constructors, to prevent implicit conversions.

Test: compile
Bug: 37378309
Change-Id: I3f9f8d561e84c492eafa6528db7c238da072dad8
2017-04-18 07:23:38 -07:00
Mark Salyzyn
d87d47f7dd liblog: log_time add explicit to some constructors.
Add explicit to constructors, to prevent implicit conversions.

Test: compile
Bug: 37378309
Change-Id: I3f9f8d561e84c492eafa6528db7c238da072dad8
2017-04-17 15:10:26 -07:00
Steven Moreland
d73be1b96b libcutils: compile with BOARD_VNDK_VERSION current
- moved __android_log_is_debuggable to a new public header
    (log_properties.h)
- vendor version of sched_policy uses ALOG* instead SLOG*

Test: (sanity) liblog-unit-tests
Test: (sanity) libcutils_test (noting b/b/32972117, two tests continue
  to fail)
Test: system/core as a whole makes with BOARD_VNDK_VERSION := current
  now with no problems.
Test: boots/works on internal marlin
Bug: 33241851

(cherry picked from commit 1f83aa424f)

Merged-In: I5bc1f348dc0f0c8814bec5b5c3d2c52c825ab640
Change-Id: I5bc1f348dc0f0c8814bec5b5c3d2c52c825ab640
2017-04-17 14:44:17 -07:00
Steven Moreland
1f83aa424f libcutils: compile with BOARD_VNDK_VERSION current
- moved __android_log_is_debuggable to a new public header
    (log_properties.h)
- vendor version of sched_policy uses ALOG* instead SLOG*

Test: (sanity) liblog-unit-tests
Test: (sanity) libcutils_test (noting b/b/32972117, two tests continue
  to fail)
Test: system/core as a whole makes with BOARD_VNDK_VERSION := current
  now with no problems.
Test: boots/works on internal marlin
Bug: 33241851

Change-Id: I5bc1f348dc0f0c8814bec5b5c3d2c52c825ab640
2017-04-17 12:18:36 -07:00
Mark Salyzyn
01bdb04be6 liblog: allow event tags to include some punctuations
event_log_tag parser complains about a period (.) in the name,
we would consider such an enhancement to the tag names possible.
I expect we would want to be able to support alphanumerics,
underscore (_), period (.), minus (-), at (@) and comma (,) for
starters as they are present in the other text log buffer tags.

We introduce a local endOfTag function that is used during parsing and
during android_lookupEventTagNum for submitting new tags.  This
function caused us to enforce const char more closely.  By filtering
in both places we resolve an issue that could have plagued us if
garbage requests were made.

Test: gTest liblog-unit-tests, logd-unit-tests & logcat-unit-tests
Bug: 31456426
Change-Id: I596b8706e843719ddac07ec40e1cd2875c214bed
2017-04-14 12:56:06 -07:00
Mark Salyzyn
5768d3d976 liblog: logprint supports number of seconds time event field
Add s to report time in seconds.  The time could be a period, duration
or monotonic, expanded to seconds, minutes, hours and days.  gTest has
to acquire a dynamic tag allocation as there are no users of this
feature yet.

Looking to the future, audio media logging has binary content similar
to the binary events structures Android logging uses and they have
a definition of a duration field in their internal binary logging, so
may be of use when we unify the logs.

Test: gTest logcat-unit-tests --gtest_filter=*.descriptive
Bug: 31456426
Change-Id: I262c03775983b3bc7b1b00227ce2bb2b0f357bec
2017-04-14 12:54:25 -07:00
Mark Salyzyn
7ecfd6ac10 liblog: android_log_event_list class permit -EBUSY retry
write() method was one-shot, a second shot on -EBUSY would always
return -EBUSY even if successful.  Reset internal error if -EBUSY
when retransmitting.  write() now reports a positive count for
transmission success.  Composition errors trump transmission errors.

Test: gTest logcat-unit-tests --gtest_filter=*.descriptive while
      under heavy DOS stress levels of logging.
Bug: 31456426
Change-Id: Ib1920c3f10cf1df8ad8eb6a884724794b577b29d
2017-04-13 13:16:59 -07:00
Dan Willemsen
ab89b34b6f Remove .(ll)ndk suffix from (ll)ndk_library
Soong handles these automatically now.

Bug: 33241851
Test: Android-aosp_arm.mk is the same before/after
Test: build.ninja is the same before/after
Test: build-aosp_arm.ninja is the same before/after
Merged-In: Ica4eedda51bb34db2f39d2c64ea436e1f633bfc3
Change-Id: Ica4eedda51bb34db2f39d2c64ea436e1f633bfc3
2017-04-11 15:14:28 +00:00
TreeHugger Robot
ce4c78224d Merge changes from topic 'llndk_rename' into oc-dev
* changes:
  Remove .(ll)ndk suffix from (ll)ndk_library
  Remove .(ll)ndk suffix from (ll)ndk_library
2017-04-11 07:22:26 +00:00
Mark Salyzyn
b07c58758b Merge "liblog: adapt to removal of property name size limit" into oc-dev 2017-04-10 21:15:27 +00:00
Dan Willemsen
c8202dc5f7 Remove .(ll)ndk suffix from (ll)ndk_library
Soong handles these automatically now.

Bug: 33241851
Test: Android-aosp_arm.mk is the same before/after
Test: build.ninja is the same before/after
Test: build-aosp_arm.ninja is the same before/after
Change-Id: Ica4eedda51bb34db2f39d2c64ea436e1f633bfc3
2017-04-10 12:54:31 -07:00
Dan Willemsen
38b4a9265d Add LLNDK liblog stub library for the VNDK
This replaces the liblog_vndk_headers with a true stub library that
exports the vndk headers, and exports the vndk-specific set of symbols.

Test: generated NDK stub maps are the same before/after
Test: aosp_arm; m -j
Test: Enable BOARD_VNDK_VERSION on aosp_arm; m -j (with other changes)
Change-Id: I9037241963b3872a3bc7cf7ab36a70dd4ddcf9bc
(cherry picked from commit 28dab34cbb)
2017-04-07 20:35:02 -07:00
Dan Willemsen
f8111b7df8 Merge "Add LLNDK liblog stub library for the VNDK" 2017-04-07 21:21:32 +00:00
Mark Salyzyn
c18f3102da liblog: adapt to removal of property name size limit
There is no longer a name size limit to the properties.

Test: gTest liblog-unit-tests, logd-unit-tests and logcat-unit-tests
Test: liblog-benchmarks BM_is_loggable
Bug: 36696208
Change-Id: I80706a48583192b21f532a06cb8fa183a34e5f76
2017-04-07 11:29:44 -07:00
Mark Salyzyn
d24dc95e87 liblog: adapt to removal of property name size limit
There is no longer a name size limit to the properties.

Test: gTest liblog-unit-tests, logd-unit-tests and logcat-unit-tests
Test: liblog-benchmarks BM_is_loggable
Bug: 36696208
Change-Id: I80706a48583192b21f532a06cb8fa183a34e5f76
2017-04-07 18:18:18 +00:00
Dan Willemsen
28dab34cbb Add LLNDK liblog stub library for the VNDK
This replaces the liblog_vndk_headers with a true stub library that
exports the vndk headers, and exports the vndk-specific set of symbols.

Test: generated NDK stub maps are the same before/after
Test: aosp_arm; m -j
Test: Enable BOARD_VNDK_VERSION on aosp_arm; m -j (with other changes)
Change-Id: I9037241963b3872a3bc7cf7ab36a70dd4ddcf9bc
2017-04-05 16:42:40 -07:00
Mark Salyzyn
191afba9bd liblog: worry over resource leaks
Add comments so that future selves can clearly see there are no file
descriptor resource leaks on normal return.

SideEffects: None
Test: Build
Change-Id: Ieec504fea00fb849cdb69c669655a918d1334e61
2017-04-05 13:02:08 -07:00
Rubin Xu
08c662c762 Fix liblog#__security failure
Update pid and gid value after calling setuid()

Bug: 36480230
Test: cts-tradefed run cts -m CtsLiblogTestCases -t liblog#__security_buffer
Change-Id: I707f7c724d64236ec17f2d978c85883a7b4f180f
Merges-In: I707f7c724d64236ec17f2d978c85883a7b4f180f
2017-04-05 11:30:06 +01:00
Rubin Xu
235cf8d729 Fix liblog#__security failure
Update pid and gid value after calling setuid()

Bug: 36480230
Test: cts-tradefed run cts -m CtsLiblogTestCases -t liblog#__security_buffer
Change-Id: I707f7c724d64236ec17f2d978c85883a7b4f180f
Merges-In: I707f7c724d64236ec17f2d978c85883a7b4f180f
2017-04-05 11:27:48 +01:00
Mark Salyzyn
54f20c5553 Merge "liblog: Speed up and extend the radio log redirect code" 2017-04-03 14:21:57 +00:00
Mark Salyzyn
fe8c96d152 liblog: benchmark add BM_log_event_overhead_42 for a well known tag
Measure the cost of using a known test event log tag from
system/core/logcat/event.logtags:

42    answer (to life the universe etc|3)

Test: liblog_benchmarks BM_log_event_overhead_42
Bug: 36683634
Change-Id: Ibd4be82bebfcedd381c84e8078cf6d05a636aa98
2017-03-31 13:25:36 -07:00
Mark Salyzyn
525b34d142 liblog: Speed up and extend the radio log redirect code
This code was supposed to be deprecated in time.  Let's make it more
efficient and add QC_RIL prefix to the list of catches to redirect
from the main logs to the radio logs.

Test: gTest liblog-unit-tests
Change-Id: I38b371b25da472ec77cbde4affeebf2eafcf6155
2017-03-31 13:10:18 -07:00
Mark Salyzyn
ef5d981977 liblog: tests: liblog.__security property failure
CTS tests are failing to set ro.device_owner property.

Test: gTest liblog_unit_tests --gtest_filter=liblog.__security
Bug: 36480230
Change-Id: Icafea9f7488ce9c4ea47d42dc08505bc0cf99a3e
2017-03-21 15:22:29 -07:00
Mark Salyzyn
5707524003 liblog: test: *.android_errorWriteWithinfoLog__android_logger_list_read__*
We would experience failures as test runs interfere with each other.
Create a unique tag for each test run signature.  Switch from using
TEST_PREFIX to TEST_LOGGER to identify the logger transport being
inspected and make that part of the signature.  Make sure 32 bit and
64 bit tests do not interfere.

Test: gTest liblog-unit-tests
      cts-tradefed run cts -m CtsLiblogTestCases
Bug: 36232924
Change-Id: I4d58242e5ef8e68e2d4b27cecf538938e17acf3f
2017-03-17 10:41:39 -07:00
Mark Salyzyn
58aaee8eb1 liblog: tests: __security and enoent failures
- __security test to allow 20ms resting time after setting ro.device_owner
- enoent test resort to using "su" command if we are not root to start
  and stop the logger.
- Add some instrumentation to guide us in the future if issues.

Test: gTest liblog-unit-tests
      cts-tradefed run cts -m CtsLiblogTestCases
Bug: 36232924
Change-Id: I6b926a1913497f7e6204493fc744ee6c454a5ce4
2017-03-17 09:11:45 -07:00
Mark Salyzyn
c500abb40b liblog: test: __android_log_btwrite__android_log_close precharge
TEST_PREFIX missing before operations on
liblog*.__android_log_btwrite__android_log_close tests

Test: gTest liblog-unit-tests
Bug: 27405083
Change-Id: Iaddc4e1b1f9afcfd8231c3921605fecefd2b56bf
2017-03-13 16:29:04 -07:00
Mark Salyzyn
81321a7980 liblog: replace "frontend" with "transport"
We still do not have any users of the 'frontend' interface, let's
right a wrong and rename it to 'transport' as it makes more sense.
Renames android_log_set_frontend, android_log_get_frontend and
include/log/log_frontend.h.

SideEffects: None
Test: gTest liblog-unit-tests
Bug: 27405083
Change-Id: I7c1c0f3dfdc7cf047285403e306edbd16ad1324d
2017-03-09 09:36:34 -08:00
Mark Salyzyn
04bbc8ea45 liblog: stay away from C++ keyword private
Replace with void* private with priv in context structure.

SideEffects: None
Test: gTest liblog-unit-tests
Bug: 27405083
Change-Id: I670cb0b7fb2f3085ea13b4ac836d84239a3c8572
2017-03-09 09:36:34 -08:00
Mark Salyzyn
2ed51d708e liblog: specify clang format
Switch coding style to match

SideEffects: None
Test: compile
Bug: 27405083
Change-Id: Id426d5c5e3b18f2ceec22b31bbc9781aabf6bcca
2017-03-09 09:36:19 -08:00
Mark Salyzyn
4d99c986d9 liblog: add LOGGER_STDERR frontend
Standalone, this logger provides no end-to-end capability.  Only
provides a writer, no reader transport.  All output goes, logcat-like,
into the stderr stream.  Output can be adjusted with environment
variables ANDROID_PRINTF_LOG and ANDROID_LOG_TAGS.

liblog_*.__android_log_bswrite_and_print___max print fails if a string
member is truncated with "Binary log entry conversion failed" and -1.
We expose the truncated content in the tests and in LOGGER_STDERR.

The purpose of this transport selection is for command-line tools,
providing a means to shunt the logs to be mixed in with the tool's
error stream.

Test: gTest liblog-unit-tests
Bug: 27405083
Change-Id: If344b6e3e67df2dc86ce317cfad8af8e857727b7
2017-03-08 07:17:31 -08:00
Mark Salyzyn
b1d150bc42 liblog: logprint, error return and truncated data
android_log_processBinaryLogBuffer and android_log_processLogBuffer
error return should have message and messageLen fields set to zero,
or to a valid-but-truncated buffer so that we can discern the
difference.  This will resolve an issue with reporting content from
an uninitialized field in liblogcat should caller add --debug flag.

To enhance the debugging capability, truncated string events because
of the logger limits are provided rather than dropping the field, but
still with an error return.

Some minor coding style issues resolved. Add required, or remove
extraneous spaces.  Use C-style comments only.

Test: gtest liblog-unit-tests
Bug: 27405083
Bug: 35326290
Change-Id: I4a7ddd7278fb1c582f921e1ba10e0765fadb791b
2017-03-03 11:10:11 -08:00
Mark Salyzyn
2a0044e4b0 liblog: event log tags cache miss call logd for update
Deal with cache miss in the event tag map resources and switch to
"Plan B" to ask long-path to logd for a determination on the tag,
name and format.

logcat-unit-tests liblogcat.descriptive does an under-the-hood call
to logd to add a new logtag but the in-process mapping fails to
pick it up because the /dev/event-tag-map map is SHARED PRIVATE for a
few moments to garner some (linux) efficiency with other copies that
are in the process.  Without the workaround of marking the mapping
dirty to be reread, we are using this change as the proper workaround
that fixes the later parts of this test.

Test: gTest logcat-unit-tests --gtest_filter=liblogcat.descriptive
Bug: 31456426
Bug: 35326290
Change-Id: Ibe54d4df00ed92248e1e644ecebc95f60b222b4d
2017-02-28 14:23:18 -08:00
Mark Salyzyn
8dcd94b2cd liblog: logprint followup
Add comment and braces to add maintenance clarity.

Test: gTest logcat-unit-tests
Bug: 35326290
Change-Id: Ie25b42faba19ae3cf52d4c6cefc4fc539ec23e79
2017-02-22 14:16:31 -08:00
Mark Salyzyn
d69e801fe8 liblog: Harden log_id check.
Logd currently checks against LOG_ID_MAX and LOG_ID_KERNEL to
determine if a given log_id is available.  liblog uses only
LOG_ID_KERNEL.  While this matches with the comments in log/log_id.h
to always keep LOG_ID_KERNEL at the end it does not match with other
checks that logd makes, causing inconsistent behavior.  This
inconsistency is noticable on devices that errantly rewrite
LOG_ID_MAX to not equal LOG_ID_KERNEL + 1.  For log buffers with
id's greater than LOG_ID_KERNEL, liblog reports that logd is
unavailable while logd would accept the request.

The guideline is to not use buffer ids above LOG_ID_KERNEL.
This hardening change prevents an inconsistency that results if these
guidelines are not followed.  Partners are urged instead to increase
LOG_ID_KERNEL locally to match their LOG_ID_MAX - 1 when they add new
local log buffers in their private builds.

Signed-off-by: Evan Ralston <eralston@amazon.com>
Signed-off-by: Mark Salyzyn <salyzyn@google.com>
Test: compiles. no functional change
Change-Id: Icd4b12ac79c1e5cd1d8a32f67a9795797580aad5
2017-02-21 22:29:19 +00:00
Treehugger Robot
2bc8e32242 Merge "Revert "Check against LOG_ID_MAX instead of LOG_ID_KERNEL"" 2017-02-14 23:08:16 +00:00
Mark Salyzyn
f8fc6f1870 Revert "Check against LOG_ID_MAX instead of LOG_ID_KERNEL"
causes a regression, logcat -b kernel does not work.

Check should have landed in logd_writer.c

This reverts commit 2c2337a293.

Change-Id: I1004b44ecc87f5d83d1c4463dd8b1ac16499706d
2017-02-14 21:00:57 +00:00
Treehugger Robot
9fcabf739b Merge "Check against LOG_ID_MAX instead of LOG_ID_KERNEL" 2017-02-10 01:14:23 +00:00
Mark Salyzyn
7100288532 liblog: add local_logger
- Create the local-only logger module
- Add LOGGER_LOCAL flag to android_set_log_frontend to enable
- Permit log reader for host compilation

android_set_log_frontend(LOGGER_LOCAL) will result in logs going
into application local memory.  logcat can not retrieve the data,
the user must utilize the log reading interface directly to
acquire their own logs.  Some local logger tests dropped as they
represent testing other liblog facilities.  Other local logger
tests dropped because we make the conscious decision to not
support LOG_ID_SECURITY logging.

ToDo: Some local logger tests dropped because of missing
      functionality associated with blocking reader.

Test: gTest libcutils-tests, logd-unit-tests, liblog-unit-tests,
      logcat-unit-tests, liblog-benchmarks and CtsLiblogTestCases_list
Bug: 27405083
Change-Id: Ia23b932af9e05756eaa60bab9139876b14faf72d
2017-02-08 15:07:06 -08:00
Mark Salyzyn
96432fc665 liblog: add __android_log_config_*_close()
Add __android_log_config_read_close() and
__android_log_config_write_close().  Fortify the list macros
to detect for list corruption, looking for entries pointing
to themselves, deleted entries in list.

Test: gTest liblog-unit-tests
Bug: 27405083
Change-Id: I33e8a0cae7e202f1989ddd7c2a96752b44c8e746
2017-02-08 13:37:44 -08:00
Mark Salyzyn
cf983bcbae liblog: add android_log_logger_list management
Add list of android_log_logger_list entities as a way of
accessing the list of transport contexts from within
one of the transports.  This will enable us to iterate back
to an internal transport context which may house a last index
or signalling semaphore to propagate a wakeup on a blocking
read.

Test: gTest libcutils-tests, logd-unit-tests, liblog-unit-tests,
      logcat-unit-tests
Bug: 27405083
Change-Id: I0a5e793946c020d97ffe10192369998e4ed92a83
2017-02-08 13:37:44 -08:00
Mark Salyzyn
62d0d2d683 liblog: add logprint to host build
- cleanup of some style issues
- resolve a few minor bugs
- add -lrt for host so that clock_gettime can be issued
- enable write-only logging, logprint and event list
  handling tests for host consumption.

NB: CtsLiblogTestCases_list is only outlet for host testing of
    the interfaces, but it is not part of any automated testing

Test: gTest liblog-unit-tests, liblog-benchmarks and
      CtsLiblogTestCases_list && build mmma system/core/liblog
Bug: 27405083
Change-Id: I13db1f45f67569407587a5a909248de33809b8cf
2017-02-08 13:37:44 -08:00
Mark Salyzyn
8f2492f582 liblog: benchmark: Use local LOGGER_NULL frontend
Additional benchmarks to check the effects and performance of the
frontend changes.

Test: manual liblog-benchmarks
Bug: 27405083
Change-Id: I2a9dba81b70e9d71cdb8de1b35e8dff099ad6038
2017-02-08 13:37:44 -08:00
Mark Salyzyn
850d06e1c9 liblog: Add android_set_log_frontend
android_set_log_frontend allows one to select LOGGER_DEFAULT,
LOGGER_LOGD or LOGGER_NULL, the latter allows a runtime mechanism to
turn logging on or off.  LOGGER_DEFAULT is LOGGER_LOGD.

Test: gTest liblog-unit-tests notably liblog.android_set_log_frontend
      and liblog-benchmarks before and after.
Bug: 27405083
Change-Id: I365dbee9f7d83112da0ef8d1cace748d247773c8
2017-02-08 13:37:41 -08:00
Treehugger Robot
a3b6d30ba7 Merge "liblog: fix an undefined-behavor in __write_to_log_daemon()" 2017-02-08 17:21:58 +00:00
Ting-Yuan Huang
6efb877973 liblog: fix an undefined-behavor in __write_to_log_daemon()
The behavior of passing NULL to c-string functions is undefined.

Test: passed clang-tidy checks
Bug: none

Change-Id: Ie7bcc43cd19bc4a1c314381af3929eae0a6154b9
2017-02-07 16:42:53 -08:00
Ting-Yuan Huang
106c3e6189 liblog: fix a memory leak in __android_log_pmsg_file_write()
Free the strdup()-ed filename before returning error.

Test: passed clang-tidy checks
Bug: none
Change-Id: I555492cb4e50400db758f7c721647a8747874a01
2017-02-07 15:53:32 -08:00
Mark Salyzyn
7048f0b1cb liblog: logger.h fortify comments
Test: none
Bug: 27405083
Change-Id: I88ae9f33daa457454edfc5e95cb9e9e74e8cd5f0
2017-02-07 14:16:09 -08:00
Evan Ralston
2c2337a293 Check against LOG_ID_MAX instead of LOG_ID_KERNEL
Logd currently checks against LOG_ID_KERNEL to determine if a given
log_id is available. While this matches with the comments in log.h to
always keep LOG_ID_KERNEL at the end it does not match with other
checks that Logd makes causing inconsistent behavior. This
inconsistency is noticable on devices with log buffers with id's
greater than LOG_ID_KERNEL and liblog reports that logd is unavailable
while logd would accept the request.

Test: compiles. no functional change

Change-Id: I0302d9e3f2657706fdf778f1e78e5604abf566e2
2017-02-07 10:46:02 -08:00
Elliott Hughes
5bae1b866d Make __android_log_assert behave more like libc asserts.
If we don't output to stderr too, not only is it annoying to shell users (who
won't see anything), it prevents us from writing better gtests that actually
make assertions about the assert message.

Bug: http://b/23675822
Test: libutils tests still pass
Change-Id: I62b3144c385cba4dde485f0b0f9b42aeaef51e9a
2017-02-06 10:54:00 -08:00
Mark Salyzyn
c9e5f37166 liblog: add android_lookupEventTagNum
android_lookupEventTagNum added.  Adds support for creating a new
log tag at runtime, registered to the logd service.

Tested on Hikey, all services stopped, shell only access, CPUs not
locked (there is enough repeatability on this platform).

$ /data/nativetest64/liblog-benchmarks/liblog-benchmarks BM_lookupEventTagNum

                          iterations      ns/op
Precharge: start
Precharge: stop 231
NB: only Tag matching, linear lookup (as reference, before unordered_map)
BM_lookupEventTagNum         1000000       1017
NB: unordered_map with full Tag & Format lookup, but with Tag hashing
BM_lookupEventTagNum         2000000        683
NB: with full Tag & Format hash and lookup for matching
BM_lookupEventTagNum         2000000        814
NB: only Tag matching (Hail Mary path)
BM_lookupEventTagNum         5000000        471

Because the database can now be dynamic, we added reader/writer locks
which adds a 65ns (uncontended) premium on lookups, and switch to
check for an allocation adds 25ns (either open code, or using
string_view, no difference) which means our overall speed takes 90%
as long as the requests did before we switched to unordered_map.
Faster than before where we originally utilized binary lookup on
static content, but not by much.  Dynamic updates that are not cached
locally take the following times to acquire long path to logd to
generate.

BM_lookupEventTag           20000000         139
BM_lookupEventTag_NOT       20000000         87
BM_lookupEventFormat        20000000         139
BM_lookupEventTagNum_logd_new   5000         335936
BM_lookupEventTagNum_logd_existing 10000     249226

The long path pickups are mitigated by the built-in caching, and
the public mapping in /dev/event-log-tags.

SideEffects: Event tags and signal handlers do not mix
Test: liblog benchmarks
Bug: 31456426
Change-Id: I69e6489d899cf35cdccffcee0d8d7cad469ada0a
2017-02-02 15:21:15 -08:00
Mark Salyzyn
7da7fab790 liblog: add /dev/event-log-tags for Tag Map
android_openEventTagMap(NULL) will open and mix content from
/system/etc/event-log-tags and /dev/event-log-tags.  Only
reports identicals if global.

Test: gTest logd-unit-tests and liblog-unit-tests, liblog-benchmarks.
Bug: 31456426
Change-Id: Ic17d52a7829a4daaf013828d08fc1c09446ae8ef
2017-02-02 14:24:26 -08:00
Treehugger Robot
26a714a0ab Merge "logcat: test: inject() tuning" 2017-01-31 15:59:22 +00:00
Mark Salyzyn
9b4d7e1c38 logcat: test: inject() tuning
Add a hidden -v nsec flag to logcat (actually logprint in liblog.so)
so that we can do more exacting tests of logcat.tail_time.  Halve the
spam pressure of logcat.tail_* in inject() routine, and give us a few
more retries at the higher counts.  Add instrumentation to
logcat.logrotate failures.  Add inject for logcat.year test.

Test: gTest logcat-unit-tests
Bug: 34454772
Change-Id: If6f3bd21892c8a2b9ccee8c8bbf592a1ae0b2a57
2017-01-30 15:42:56 -08:00
Mark Salyzyn
bdac221cc3 Revert "Continue using the legacy NDK android/log.h."
Use refreshed android/log.h for NDK

This effectively a modern revert of the commit
b7c3996f7c

Test: build
Bug: 30465923
Bug: 34250038
Change-Id: I7d4a5134bb711051283c36a2d5bc803436dca12e
2017-01-30 22:14:59 +00:00
Treehugger Robot
ff21dba167 Merge "liblog: export log/log_read.h to vndk" 2017-01-27 02:14:34 +00:00
Treehugger Robot
296f7dad19 Merge "Don't use private libc++ macros." 2017-01-27 00:42:21 +00:00
Mark Salyzyn
9b844bc6e1 liblog: export log/log_read.h to vndk
Test: gTest liblog-unit-tests
Bug: 34250038
Change-Id: I2904b950eb399a4f34c5da31b51703e8f2d5ea93
2017-01-26 16:10:59 -08:00
Dan Albert
9ccdd5fb17 Don't use private libc++ macros.
The visibility macros just expand to the defaults, so this isn't
needed anyway.

Test: mm
Bug: http://b/34740564
Change-Id: If0ba6b412554300823219405c1e801ceec747dd0
2017-01-26 14:58:26 -08:00
Mark Salyzyn
21de8aca67 liblog: add log/log_read.h
Move log reading definitions to their own home.

struct logger_entry
struct logger_entry_v2
struct logger_entry_v3
struct logger_entry_v4
LOGGER_ENTRY_MAX_PAYLOAD
LOGGER_ENTRY_MAX_LEN
struct log_msg
android_logger_get_id()
android_logger_clear()
android_logger_get_log_size()
android_logger_get_log_readable_size()
struct logger_list
android_logger_get_statistics()
android_logger_get_prune_list()
android_logger_set_prune_list()
android_logger_list_alloc()
android_logger_list_alloc_time()
android_logger_list_free()
android_logger_list_read()
android_logger_open()
android_logger_list_open()

Deal with a possible scenario where fcntl.h was not included at the
top of the source files, and log/log_read.h inclusion of fcntl.h
conflicts with a source file inclusion of sys/cdefs.h definition of
__unused macro.

Test: gTest liblog-unit-tests --gtest_filter=\
      liblog.__android_log_write__android_logger_list_read:\
      liblog.android_logger_get_
Bug: 34250038
Change-Id: Ib33544171563d6a351164754c254c4385686025b
2017-01-26 21:13:31 +00:00
Mark Salyzyn
52c140ca72 liblog: add log/log_time.h
Move log_time definitions to their own home.

struct log_time

Test: gTest liblog-unit-tests --gtest_filter=liblog.log_time
Bug: 34250038
Change-Id: I400cf4cc865d1c167699a4654ecb69455a18e604
2017-01-25 15:41:43 -08:00
Mark Salyzyn
c89fea44ac liblog: add log/log_radio.h
Move RLOG logging macros to their own home.

RLOGV
RLOGV_IF
RLOGD
RLOGD_IF
RLOGI
RLOGI_IF
RLOGW
RLOGW_IF
RLOGE
RLOGE_IF

Test: gTest liblog-unit-tests --gtest_filter=liblog.RLOG
Bug: 34250038
Change-Id: Iad5b5abf23c7a537ff5293bb55a6633dce2e837d
2017-01-25 15:41:43 -08:00
Mark Salyzyn
dd61659e73 liblog: add log/log_system.h
Move SLOG logging macros to their own home.

SLOGV
SLOGV_IF
SLOGD
SLOGD_IF
SLOGI
SLOGI_IF
SLOGW
SLOGW_IF
SLOGE
SLOGE_IF

Test: gTest liblog-unit-tests --gtest_filter=liblog.SLOG
Bug: 34250038
Change-Id: I456c7ad23152dc1c7b39143d87401a8737e24d64
2017-01-25 15:41:43 -08:00
Mark Salyzyn
3cdbdd522f liblog: add log/log_id.h
Move common log_id_t and simple internal support function definitions
that use it from log/log.h to log/log_id.h.

log_id_t
__android_log_buf_write
__android_log_buf_print
android_name_to_log_id
android_log_id_to_name

Test: gTest liblog-unit-tests --gtest_filter=\
      liblog.log_id:\
      liblog.__android_log_buf_print:\
      liblog.__android_log_buf_write:\
      liblog.__android_log_buf_print__concurrent64
Bug: 34250038
Change-Id: Iad3704cc72943a3094e1193a6d032c7f29a6cd5c
2017-01-25 15:41:43 -08:00
Mark Salyzyn
5c967da341 ndk: reverse course on android/log.h
move LOG macros to log/log_main.h

move include/android/log.h to liblog/include/android/log.h

Test: compile of all components and gTest liblog-unit-tests
Bug: 34250038
Bug: 30465923
Change-Id: If182dd9b83689e8b7bc1a44b2f5d913c7ee5eeee
2017-01-25 15:41:43 -08:00
Vijay Venkatraman
651f8383e6 Revert "Revert "Exporting C headers from system/core""
This reverts commit a3f2be2b73.

Test: compile
Change-Id: I04b3a8e47e1fa3eb9d80c14ae3a90c68a780e858
2017-01-25 12:50:29 -08:00
Vijay Venkatraman
22b7f76a00 Merge "Revert "Exporting C headers from system/core"" 2017-01-25 00:53:07 +00:00
Vijay Venkatraman
a3f2be2b73 Revert "Exporting C headers from system/core"
This reverts commit 3c6763ca21.

Change-Id: If3b3e106478d28a5df927d57649abdca0a99dd0e
2017-01-25 00:44:08 +00:00
Evgenii Stepanov
f38ae34bbc Merge "Don't disable all sanitizers in liblog, just asan." 2017-01-24 23:00:54 +00:00
Evgenii Stepanov
ffdabdc6f2 Don't disable all sanitizers in liblog, just asan.
ASan runtime library depends on liblog, so we have to disable ASan,
but nothing else.

Bug: 33091541
Test: SANITIZE_TARGET=address keeps working
Change-Id: I6e22925b7f1d5ec86fe1bd8c00dba4c3e86ddf3f
2017-01-24 12:57:23 -08:00
Vijay Venkatraman
3c6763ca21 Exporting C headers from system/core
Moved headers from include/libcutils and include/liblog to
libcutils/include and liblog/include respectively, so they can be
exported via these libs. They needed to be moved since Soong does
not allow export from external folder.

Added symlink from old locations. They are needed since Soong
includes system/core/include by default. Once all modules are
cleaned up to explicitly add the required libs, the symlinks will be
removed.

Also added liblog_vndk_headers that exports a special log/log.h for
VNDK.

Moved headers of libcutils to libcutils_headers. They should be used
by modules for header-only inlines. Added libcutils_headers as
dependency of libcutils.

Added libcutils_vndk_headers that exports a special cutils/log.h
deprecating usage of the file. A later CL will deprecate the one in
libcutils_headers

Test: Add above libs to shared lib of local module
Change-Id: I6e1f9c5f23d8b6eae13dc3b7e5dfe7fae93b8510
2017-01-22 19:45:38 -08:00
Mark Salyzyn
142b43d4ab liblog: BM_log_latency improvement
This reduces BM_log_latency from ~300ns to ~100ns.  Because, well, we
read the clock earlier and that is what BM_log_latency tries to
measure.  The one major improvement in the switch from kernel logger
to user space logger was that we picked up the timestamp in the
context of the caller before doing anything else, but alas changes
over time neglected this fact and placed isloggable checking ahead
of this important fact.

Test: liblog_benchmarks, check results
Change-Id: I4bc9fc3cf8b1659e88417d967b1d0f3743f9e456
2017-01-20 17:53:27 +00:00
Jorge Lucangeli Obes
f4ae42f6a8 Check the return value of setuid(2).
I'd like to mark setuid() WARN_UNUSED_RESULT to prevent security bugs.
This line would break because the file is compiled with -Werror.

Bug: 34251640
Test: Build, run unit test.
Change-Id: Ibb6fa5e5b899d47f77f2a32da762165de310101d
2017-01-13 15:43:45 +00:00
Mark Salyzyn
65e1e6284c liblog: retry -ENOTCONN | -ECONNREFUSED | -ENOENT indefinitely
Deal with recovering after transitory failures surrounding logd
crash or recovery.  Improve the chances that the logging functions
can work in a signal handler, not officially supported, but making
sure logging is not blamed for system lockups when misused.

Reorder gTests so that setuid(AID_SYSTEM) is performed after
liblog.enoent test, and that this occurs after other tests that
like to see buffers with content in them as we stop logd.

Test: gTest liblog-unit-tests --gtest_filter=liblog.enoent
Bug: 33755074
Change-Id: I66f88599534614b7b61da6b2ae5fe099ebaced3a
2017-01-09 15:51:09 +00:00
Mark Salyzyn
b52f445dbb liblog: test: switch to private event structures
Some tests use hard-coded offsets to interpret the binary
events buffers.  Switch to using the private event structures
to access the components of common event messages.

Test: gTest liblog-unit-tests
Bug: 33755074
Change-Id: I17447814583099d5ec417a54389e962158456005
2017-01-06 22:13:34 +00:00
Dan Albert
9a41bcecc6 Unversion NDK stub libraries.
The system versions of these libraries aren't versioned yet.

Bug: https://github.com/android-ndk/ndk/issues/278
Test: make ndk
Change-Id: Icf5ff9921441d3e252771aef37002c772c08cbd0
2017-01-06 11:04:15 -08:00
Elliott Hughes
9b3b119912 Don't use bare noreturn in log.h.
toybox has a #define noreturn that trips over this.

Also move `format` out of the way, just in case.

Bug: https://github.com/android-ndk/ndk/issues/271
Test: builds
Change-Id: Ib8811136b4b422ff74625509539a5464a3c9af18
2017-01-03 13:17:42 -08:00
Mark Salyzyn
af3503cff4 liblog: test failures due to permission issues
Test: gTest liblog-unit-tests passes
Change-Id: Ia9452b3ee9e6068723e8bef48c4d88d3769951a8
2016-12-27 10:01:42 -08:00
Mark Salyzyn
fc148f7f33 liblog: add IF_ALOG_RATELIMIT
IF_ALOG_RATELIMIT()
    ALOGE("Only one message globally using IF_ALOG_RATELIMIT()"
          " in the process may appear ever ten seconds,"
          " (%s)", strerror(errno));

static time_t last; /* initial state zero */
IF_ALOG_RATELIMIT_LOCAL(60, &last)
    ALOGE("Only one message locally may appear every minute,"
          " (%s)", strerror(errno));

These new calls are guaranteed not to affect the value of a
non-zero errno to simplify logging of errors.  However, the
ALOGE calls in the above examples may update the errno value
upon their return.

Test: gTest liblog-unit-tests --gtest_filter=liblog.__android_log_ratelimit
Bug: 33535908
Change-Id: Id8cc192fc7d14504ffd418933cf88ae945c089f2
2016-12-21 21:36:14 +00:00
Mark Salyzyn
5bd8f2d956 liblog: pmsg read permissions for AID_LOGD
Test: gTest liblog-unit-test and logd-unit-tests
Bug: 31456426
Change-Id: I7a2fe8245ecd651883f7851ce71b6c45e373af82
2016-12-19 15:57:01 +00:00
Mark Salyzyn
774e04f779 liblog: move log_is_loggable.c to properties.c
Just makes sense cleanup

Test: gTest liblog-unit-tests
Bug: 33535908
Change-Id: I85de049f3cd73a473d56db5970d42eee5f9f70a8
2016-12-16 08:43:56 -08:00
Treehugger Robot
8b99ef6c21 Merge "liblog: event_tag_map use unordered_map" 2016-12-16 01:57:03 +00:00
Mark Salyzyn
700fb87648 liblog: event_tag_map use unordered_map
>3 times faster access for lookup functions.  Code simplification and
C++ coding style conversion.  android_lookupEventTagNum has been
expanded to utilize the Format match, and then drops down to just
Tag match.

Performance testing on Hikey, all services stopped, shell only access,
CPU not locked had good repeatability.

$ adb reboot ; adb wait-for-device ; adb shell su root stop

Before this adjustment using binary search:

$ /data/nativetest64/liblog-benchmarks/liblog-benchmarks BM_lookupEvent*
                          iterations      ns/op
Precharge: start
Precharge: stop 231
BM_lookupEventTag           10000000        153
BM_lookupEventTag_NOT       20000000        139
BM_lookupEventFormat        10000000        153

After this adjustment strictly using std::unordered_map lookup:

$ /data/nativetest64/liblog-benchmarks/liblog-benchmarks BM_lookupEvent*
                          iterations      ns/op
Precharge: start
Precharge: stop 231
BM_lookupEventTag           50000000         56
BM_lookupEventTag_NOT      100000000         21
BM_lookupEventFormat        50000000         56

Test: gTest logd-unit-tests and liblog-unit-tests, liblog-benchmarks.
Bug: 31456426
Change-Id: I1cfc3d641c3ea9ab08d455efe0c844d3a6381440
2016-12-15 22:32:37 +00:00
Mark Salyzyn
a91b426268 liblog: clean up SafetyNet unit tests
Move active code into helpers.

Test: gTest liblog-unit-tests
Change-Id: I5ade96edd71b7d773386f4d99eddbad076d10405
2016-12-13 13:47:48 -08:00
Mark Salyzyn
ed9dc8abe2 liblog: switch event_tag_map.c to event_tag_map.cpp
NB: recent activities on event_tag_map.c were to allow
    this transition to be unremarkable.

Test: compile
Bug: 31456426
Change-Id: I13e1771a001874244711a5ac3023861c2a5f8c7d
2016-12-01 15:42:03 -08:00