Commit graph

293 commits

Author SHA1 Message Date
James Hawkins
0e3167e203 Revert "bootstat: Remove custom uptime parser in favor of elapsedRealtime."
This reverts commit 26f40c04c3.

This change broke the Darwin SDK target.

Test: none
Change-Id: Ia54fe2c31da8d8fa2825e023b035fb8321dcd457
2017-02-08 14:16:51 -08:00
James Hawkins
26f40c04c3 bootstat: Remove custom uptime parser in favor of elapsedRealtime.
Refactored init/utils/boot_clock into base/chrono_utils.

Bug: 34352037
Test: none
Change-Id: Ied0c00867336b85922369d7ff37520e3d28fc61e
2017-02-07 15:43:32 -08:00
Yabin Cui
0c68953778 base: support logging before enter main function.
Bug: http://b/30974760
Test: run libbase_test.

Change-Id: I3f45fc21e8fe6301b5fef027728ea91f2188911d
2017-01-25 15:50:47 -08:00
Elliott Hughes
2140782d24 bootable/recovery wants EqualsIgnoreCase.
Bug: N/A
Test: ran tests
Change-Id: I4a6ee9eba0514b8bb8fb0489f4d370964ce9c1c2
2017-01-13 18:51:32 -08:00
Elliott Hughes
a6c65704d6 Fix libbase file.Readlink test on marlin/sailfish.
Bug: http://b/33306057
Test: ran tests
Change-Id: Ie6797e71d3507572da66d6b6966f8ee9373124a4
2017-01-11 17:34:40 -08:00
Charles He
40feda6ae9 [nit] Fix typo in properties.h
Test: none
Change-Id: I6fe25bc9404c18bedc5802b3d830ede8a1bc28df
2016-12-15 10:47:32 +00:00
Stephen Hines
b0775ca517 Switch to memcpy for accessing misaligned data.
Bug: http://b/31532493

Using misaligned pointers forces us to potentially take the address of
members in a packed structure (which is now a warning/error in the
latest Clang). Using memcpy() is the proper way to handle this kind of
problem, as the compiler can insert the proper instructions (and usually
elide the memcpy() entirely).

Test: Built correctly with updated compilers.
Change-Id: Ia1f6eb62cf19404ff76b71d3c6c7ffffa1403120
2016-12-07 03:46:55 -08:00
Dan Willemsen
ab34b47b35 Enable libbase/libutils/libziparchive on host bionic
Bug: 31559095
Test: Test linux_bionic compile
Change-Id: Ib42c063532c1cbeb3e1418ab16a1fb54d5902aab
2016-11-29 13:38:53 -08:00
Elliott Hughes
42937492c8 Add StartsWithIgnoreCase/EndsWithIgnoreCase.
This has come up a couple of times now.

Bug: wanted as part of http://b/32094640
Test: ran tests
Change-Id: I51b67074b7ddeedd771d7be9651ba33e05491b33
2016-10-25 14:56:04 -07:00
Wei Wang
8c176302e6 Move CapturedStderr to test_util library
Bug: 32181382
Test: run /data/nativetest(64)/binderTextOutputTest
Change-Id: Ifb2e1f6af2c3f57b5cbed7dde65efb31253c52a2
2016-10-22 10:35:21 -07:00
Mark Salyzyn
27d2d49f48 Merge "system/core: preparation to pull back interfaces from android/log.h" 2016-10-20 17:53:45 +00:00
Yabin Cui
d55705796e Merge "libbase: add parsedouble.h." 2016-10-20 17:18:36 +00:00
Mark Salyzyn
cfd5b080af system/core: preparation to pull back interfaces from android/log.h
Point to log/log.h where necessary, define LOG_TAG where necessary.
Accept that private/android_logger.h is suitable replacement for
log/logger.h and android/log.h.

Correct liblog/README

Effectively a cleanup and controlled select revert of
'system/core: drop or replace log/logger.h' and
'system/core: Replace log/log.h with android/log.h'.

Test: compile
Bug: 30465923
Change-Id: Ic2ad157bad6f5efe2c6af293a73bb753300b17a2
2016-10-20 08:11:39 -07:00
Yabin Cui
997cba4271 libbase: add parsedouble.h.
Bug: http://b/24905115
Test: run libbase_test --gtest_filter=parsedouble.smoke.
Change-Id: I604424772f2082b420935e6647da03981c0b8929
2016-10-19 11:19:42 -07:00
Elliott Hughes
da46b392f1 Move off std::sto* function which abort on failure.
Bug: http://b/31403370
Test: builds, boots, libbase tests pass
Change-Id: I89cd7ca3d8f1c8a1bad0ddf3043439449d19a293
2016-10-13 15:34:05 -07:00
Treehugger Robot
392a2c8f0f Merge "Add 0X as a valid hex prefix for parseint" 2016-10-08 10:36:02 +00:00
Yifan Hong
89fbd6349f Add 0X as a valid hex prefix for parseint
Bug: 31983995

Test: make android.hardware.tests.expression@1.0
Change-Id: I526d73f96c519f84dec93befa442b1d2fff7979b
2016-10-07 16:50:16 -07:00
Andreas Gampe
b4e32f3b33 Base: Hand complete log message to aborter
Undo zero-termination-substitution for linebreaks when logging.
This results in handing the complete log message to the aborter.
Add a test.

Bug: 31893081
Test: mmma system/core/base && $ANDROID_HOST_OUT/nativetest64/libbase_test/libbase_test64
Change-Id: I2ef6c6351db2fd494a02985f634f439104136227
2016-10-04 19:19:59 -07:00
Mark Salyzyn
ff2dcd9af9 system/core Replace log/log.h with android/log.h
Should use android/log.h instead of log/log.h as a good example
to all others.  Adjust header order to comply with Android Coding
standards.

Test: Compile
Bug: 26552300
Bug: 31289077
Change-Id: I33a8fb4e754d2dc4754d335660c450e0a67190fc
2016-09-30 12:47:05 -07:00
Treehugger Robot
aa00f5852f Merge "Base: Remove LOG_S variants." 2016-09-26 00:37:13 +00:00
Andreas Gampe
1f5fb43047 Base: Remove LOG_S variants.
Partially reverts commit 436f5a031f.

Remove the variants taking a fully qualified LogSeverity. Instead
use a lambda with "using" statements to translate both qualified
and unqualified names into valid expressions.

Compile-time regression was measured as 0.1s for a thousand LOG
statements on a z840.

Update tests.

Bug: 31338270
Test: m
Test: mmma system/core/base && $ANDROID_HOST_OUT/nativetest64/libbase_test/libbase_test64
Change-Id: I36fdf30a9d535b19543307b85d1b3c19a97f20dd
2016-09-24 10:18:38 -07:00
Treehugger Robot
3f049c3f19 Merge "Add std::string system property functions." 2016-09-24 04:52:59 +00:00
Elliott Hughes
1e88c8c0ac Add std::string system property functions.
Makes it easier to write correct code in a world where the maximum
property key/value lengths change.

Bug: http://b/23102347
Test: libbase_test64
Change-Id: I100f00904221bbcef9e8786a4e6e30428039bb49
2016-09-23 15:30:22 -07:00
Andreas Gampe
19ff8f1e57 Base: Check severity in destructor
Bug: 31338270
Test: m
Test: mmma system/core/base && $ANDROID_HOST_OUT/nativetest64/libbase_test/libbase_test64
Change-Id: Ic077822bcfd591bd11f4fa9d4b6e440b461c70c1
2016-09-23 13:31:52 -07:00
Andreas Gampe
436f5a031f Base: Add more log macros
Add WOULD_LOG to determine whether a given severity would be logged.

Add LOG_STREAM to have direct access to a logging stream.

Add LOG_S variants that take a fully qualified severity. This allows
complex expressions as parameters, e.g., ternaries for conditional
severity levels.

Add tests.

Bug: 31338270
Test: m
Test: mmma system/core/base && $ANDROID_HOST_OUT/nativetest64/libbase_test/libbase_test64
Change-Id: I242b960594e68caff6db9cd8aaa4ce8aaf90474c
2016-09-22 12:47:40 -07:00
Josh Gao
5d1b1a8b91 base: rename unique_fd::clear() to unique_fd::reset().
unique_fd is modeled on unique_ptr, so make this consistent.

Test: m checkbuild
Change-Id: Ia6a77095dc18746fbb432e96bb8dccfc049c57f6
2016-09-19 11:24:58 -07:00
Pirama Arumuga Nainar
70f281ae36 Remove mutex.h and its uses.
mutex.h is now available as a part of MinGW itself.

Test: Successful build
Change-Id: I036ee37600a39130d6fbf293398585cfc58209ca
2016-09-16 15:58:00 -07:00
Josh Gao
ffabc9651f base: add parameter that controls O_NOFOLLOW in file functions.
Bug: http://b/31491920
Change-Id: I19cb06941d87c0180ccab8bb2d85e57338811624
Test: m
2016-09-14 17:08:22 -07:00
Josh Gao
c95afaa20b Fix darwin build break.
Bug: http://b/31468413
Change-Id: I12fdf0977213eefc7043939964070025a672881a
2016-09-14 13:54:45 -07:00
Treehugger Robot
c9c555b8dd Merge changes Ie15fcb8f,I0a895911
* changes:
  base: add quick_exit emulation.
  base: extract mutex.h from logging.cpp.
2016-09-14 20:14:53 +00:00
Josh Gao
0c44256ae4 base: add quick_exit emulation.
Bug: http://b/31468413
Change-Id: Ie15fcb8ff0613d01a0eb7437a2cb37283aa52bab
Test: mma, libbase_test on Linux/Windows
2016-09-13 17:54:50 -07:00
Josh Gao
63bdcb57aa base: extract mutex.h from logging.cpp.
Extract the Windows-specific mutex implementation from logging.cpp.

Bug: http://b/31468413
Change-Id: I0a895911ec6d815b8011b09d55209b64bbf9a70e
Test: mma
2016-09-13 15:59:46 -07:00
Andreas Gampe
d8f26e2ac9 Base: Fix dangling-else in CHECK_STROP
Follow-up to commit 2527628eda.

Bug: 26962895
Bug: 31338270
Test: m
Test: mmma system/core/base && $ANDROID_HOST_OUT/nativetest64/libbase_test/libbase_test64
Change-Id: Ifd71314e146ebf3957cc053ee95ef85002c909b4
2016-09-13 14:16:37 -07:00
Andreas Gampe
2691e335fe Base: Add AbortFunction for logging
Add a hook to modify FATAL behavior. Add a test.

Bug: 31338270
Test: m
Test: mmma system/core/base && $ANDROID_HOST_OUT/nativetest64/libbase_test/libbase_test64
Change-Id: I966da319cda613738b3f2ccdac8c21900d6a5c72
2016-09-08 15:33:27 -07:00
Andreas Gampe
550829d84b Base: Add INTERNAL_FATAL to logging severity
Add the INTERNAL_FATAL level. It will print 'F' like FATAL, but
does not abort after logging.

Add a test to logging_test.

Bug: 31338270
Test: m
Test: mmma system/core/base && adb sync && adb shell /data/nativetest/libbase_test/libbase_test32
Change-Id: Idf74c08e8516881efccaefc58fa3f41d57e56396
2016-09-07 18:19:42 -07:00
Elliott Hughes
13d78e440a Clean up the libbase logging test.
Use ECMAscript regex syntax (the default!) for a simpler regex.

Also test the cartesian product of logging options, with less copy & paste
than the previous test of a subset.

Change-Id: I7aae91d276dbbb8de6173d18b5c1ceb01c1dff73
2016-09-07 16:22:40 -07:00
Andreas Gampe
7c1cdd7700 Base: Fix logging_test
Update the expected logging pattern.

Bug: 31338270
Test: mmma system/core/base && adb sync && adb shell /data/nativetest/libbase_test/libbase_test32
Change-Id: I299620669126bc0258cad6e30d5b40bff5ea92ad
2016-09-07 11:39:59 -07:00
Treehugger Robot
43824e72c7 Merge "Base: assume and use C++11 in libbase" 2016-09-01 22:32:42 +00:00
Andreas Gampe
22847131da Base: assume and use C++11 in libbase
Assume C++11 support. logging.h already used constexpr before,
macros.h now also does no longer check the language level.

Use constexpr for the logging evaluator. This allows the usage
of CHECK and co in other constexpr expressions in C++14.

Test: m checkbuild (N9)
Change-Id: Ifdffa074271fff1f9949c48829a185800ec5e524
2016-09-01 13:38:12 -07:00
Josh Gao
7307f09457 base: use _NSGetExecutablePath in GetExecutablePath
Bug: http://b/31240820
Change-Id: I0dbf95d3667c7ce7b474ddbb3f8e3ed69476d13e
Test: mma && adb kill-server && adb devices
2016-09-01 12:32:35 -07:00
Josh Gao
945d1aaa32 Merge "Add android::base::GetExecutablePath, switch adb and fastboot over." 2016-09-01 18:38:12 +00:00
Elliott Hughes
82ff315bb0 Add android::base::GetExecutablePath, switch adb and fastboot over.
We'd long had two copies of this stuff, so rather than rewrite both
Linux versions to use android::base::Readlink, let's kill the duplication
too...

Bug: http://b/30988271
Change-Id: I4de58a94a22a4b1faf969a6fc70ca1560a4d5121
2016-09-01 09:24:24 -07:00
Treehugger Robot
3f3ea50828 Merge "Base: add more thread annotations" 2016-08-31 22:23:00 +00:00
Josh Gao
ca82aa7d1e Merge "base: disallow close() on unique_fd." 2016-08-31 20:47:13 +00:00
Andreas Gampe
bc5a32e2ad Base: add more thread annotations
These are taken from ART and wrap more attributes.

Test: m
Change-Id: I545fc9ab88cf9d2db4de2cb8893e2a35f6365f51
2016-08-31 13:29:07 -07:00
Treehugger Robot
a7c4424ebc Merge "Add android::base::Readlink." 2016-08-31 17:56:40 +00:00
Elliott Hughes
d3ff6e5231 Add android::base::Readlink.
Bug: http://b/30988271
Change-Id: Ib844d7c9e33465dabf7aee5e24dc3d1d8d799abd
2016-08-31 09:35:44 -07:00
Josh Gao
6496c4bf6f base: disallow close() on unique_fd.
unique_fd's implicit conversion to int allows it to be passed to
close(2), which is dangerous because unique_fd will think that it still
has ownership of the now-closed fd. Disallow this by providing an
overload for close that's tagged with an attribute that gives a
compile-time error.

Test: m
Change-Id: I514591335b337f2f57c1df371cf3979304aea17c
2016-08-29 14:37:49 -07:00
Andreas Gampe
247924a36f Libbase: add C++11 support to DISALLOW_IMPLICIT_CONSTRUCTORS
Use delete when possible.

Test: m
Test: m test-art-host
Change-Id: Ib741564c7a31348b2f706fe55eb23d9886f865e3
2016-08-29 09:36:31 -07:00
Elliott Hughes
7bc87a5a78 Move init's kernel logging into libbase.
This will let other stuff (such as adbd and recovery) use it too.

Bug: http://b/28467098
Change-Id: Idab51f438ed3edd6fe65a56c4b396eaff5f3833e
2016-08-04 16:09:39 -07:00
Elliott Hughes
e5dd71a290 libbase should use its own logging!
Not doing so led to us using a bogus log tag.

Bug: http://b/30281203
Change-Id: I3ac91758a1a043146c65f2ae0f36fcfbe372c30f
2016-07-28 15:15:28 -07:00
Colin Cross
fc06bd0ca3 Convert libbase Android.mk to Android.bp
Change-Id: I429d0a06c5138c3e54c9d25f15adb3e2647496e1
2016-07-11 14:23:32 -07:00
Elliott Hughes
4e5fd111d8 Add timestamps to libbase's stderr logging.
adb is the client that wants this, but I'm not aware of any client that
doesn't.

Bug: http://b/28467098
Test: tested manually with cat.
Change-Id: I82c3f7ddf466a67aedfbb9010e0939a44b71d3e5
2016-06-21 14:27:16 -07:00
Chih-Hung Hsieh
c713bce901 Fix misc-macro-parentheses warnings in init and other core modules.
Bug: 28705665
Change-Id: Ice67cebb8c42538f8fb9cf1756678f41a9d68a31
2016-05-18 18:11:49 -07:00
Josh Gao
13ea01db45 adb/base: allow use of unique_fd inside adb.
adb implements its own file descriptor emulation layer on Windows,
which requires the use of adb_close instead of close throughout the
codebase. Add a template argument to unique_fd that allows for this.

Bug: http://b/28347842
Change-Id: I6397261f4973d49f2f8e04257bf67b348585bb63
2016-05-14 18:25:51 -07:00
Christopher Wiley
2a7b86337f Don't include android-base/macros.h from android-base/unique_fd.h
This prevents a ton of macro collisions when libfoo includes libbinder
includes unique_fd.h.

Bug: 27804373
Change-Id: Ide834afb1052b32e86fad3fcba10cff3dafeb899
2016-04-19 14:45:48 -07:00
Christopher Wiley
ec9ea66a2b Define LIKELY and UNLIKELY in a vendor friendly way
This prevents macro conflicts with vendor code.

Bug: 27804373
Change-Id: I759c2b7b611203d0afdc35ddd5c2adb8f942ea17
Test: Compiles when libbinder include path changes to include libbase.
2016-04-18 16:08:19 -07:00
Elliott Hughes
2c5d1d7cd9 Add operator int() to unique_fd.
Change-Id: I7512559be7befbb8772d5529e06550267a2f1543
2016-03-28 12:15:36 -07:00
Elliott Hughes
3761365735 Merge "Fix <android-base/*.h> header guards." 2016-03-26 16:08:59 +00:00
Elliott Hughes
19388fc312 Merge "Copy the good comment and warn_unused_result from ScopedFd to unique_fd." 2016-03-26 15:53:20 +00:00
Elliott Hughes
54c72aaccc Fix <android-base/*.h> header guards.
I've been meaning to do this for a while, and it came up on the bug below
that there have been conflicts with similar-named files in <base/*.h>,
so let's rule out one possible explanation.

Bug: http://b/27804373
Change-Id: I69e5d52b6260c573c308513420aee0e281426bd4
2016-03-23 15:04:52 -07:00
Elliott Hughes
c0e6e40cc9 Copy the good comment and warn_unused_result from ScopedFd to unique_fd.
Also list all known aliases of this class to increase the chances that
anyone searching for it by another name finds it anyway.

Change-Id: I58ea0a5421987fb69f93cc56252a771e9c34147e
2016-03-23 14:56:37 -07:00
Pierre Imai
e65f8bedec Merge "Add C++ thread annotations support to core." 2016-03-23 03:13:22 +00:00
Pierre Imai
021ea2d176 Add C++ thread annotations support to core.
Change-Id: I7b8940c12e0f3121d8c09d86d2d4077b0a0ce376
2016-03-23 11:23:28 +09:00
Yabin Cui
2527628eda base: Avoid compilation error when compiled with -Wdangling-else.
As logging macros uses `if xxx else yyy` style, it is reported as an
error when DCHECK() is compiled with -Wdangling-else option. Because
after preprocess, DCHECK(x) becomes:
if (EnableDChecks)
  if (x)
    ;
  else
    LogMessage(FATAL) << yyy;

This CL avoids compilation error by replacing `if xxx else yyy`
with `xxx && yyy` or `!(xxx) || yyy`.

Bug: 26962895

Change-Id: Ib0bf242cc04a238ec31a1ab66b53fc8a5b5ed28f
2016-03-21 17:46:21 -07:00
Chih-Hung Hsieh
7e0e14ca84 Make CHECK(x) work with static analyzer.
When __clang_analyzer__ is defined call abort after FATAL LogMessage.
BUG: 27379879

Change-Id: I198aad2be1191b6eb45db5333f94436f619facd9
2016-03-02 09:23:02 -08:00
Elliott Hughes
38e2b63db8 Remove libbase's libutils dependency.
Yuck.

Change-Id: If84758f25bc15d5b1a732eaccc226385f51cac13
2016-02-17 11:53:54 -08:00
Yabin Cui
b958d22310 Merge "libziparchive: port unit tests to darwin and windows." 2016-02-09 00:56:43 +00:00
Yabin Cui
8e6f722764 libziparchive: port unit tests to darwin and windows.
Also use ReadFully to replace read, because read can
return reading bytes less than requested. And use
WriteFully to replace write.

Bug: 26962895
Change-Id: Iff0b2bc6d925619a537f7fef682c2a7ad89a2dc2
2016-02-08 16:52:55 -08:00
Dan Willemsen
3f68ba4dc6 Merge "Fix windows 64-bit builds" 2016-02-08 23:40:48 +00:00
Dan Willemsen
86cf941c48 Fix windows 64-bit builds
pid_t is 64-bit in 64-bit mingw, but the windows process/thread
functions return a DWORD(uint32_t). Instead of promoting to a pid_t and
fixing the format strings, just use a uint32_t to store the values.

android_thread_id also cannot be a 64-bit pointer, so for windows just
force it to be a uint32_t.

libutils/ProcessCallStack only works under Linux, since it makes heavy
use of /proc. Don't compile it under Windows or Darwin.

Bug: 26957718
Change-Id: I4e43e7cf18a96f22b3a9a08dbab8c3e960c12930
2016-02-05 16:10:10 -08:00
Elliott Hughes
5cf0dcd5b2 Fix libbase's logging dependency.
Get liblog directly, rather than transitively through libcutils.

Change-Id: Ia08ac6f04ac68c39807989d869709bae0a051578
2016-02-04 08:24:55 -08:00
David Pursell
5f787ed2b3 base: add SystemErrorCodeToString() function.
Pulls the Windows error string generation out of adb into libbase so
that it can be used by fastboot as well. Also makes a Unix equivalent
that just wraps strerror() so that upcoming fastboot error reporting
code can be platform-independent.

The intent here is just to provide a portable way to report an error to
the user. More general cross-platform error handling is out of scope.

Bug: http://b/26236380
Change-Id: I5a784a844775949562d069bb41dcb0ebd13a32bc
2016-02-01 12:18:26 -08:00
Yabin Cui
b6e314aa86 base: add API to remove file if it exists.
It is a function needed in different places like uncrypt, simpleperf.

Bug: 26883096
Change-Id: I26f4f30e8367867a88272625f00858569fc8e950
2016-01-29 19:24:55 -08:00
David Pursell
706955ff0d base: add network address parsing function from adb.
This CL moves the network address parsing function from adb to libbase
so that it can be used by fastboot as well as adb.

libbase seemed like the right choice because:
  1. It already has some parsing functions (parseint)
  2. The net address parsing function uses the libbase string
     functions so we have a libbase dependency anyway.

The parsing function has been modified slightly to make the canonical
address optional, and debug logging on success has been removed.

For adb the only functional difference is that parsing a network
address will no longer print the result to the debug log, which seemed
unnecessary.

Bug: http://b/26236380
Change-Id: Ife6df02937225fc66de87884d3572d79c092c522
2016-01-21 20:03:33 -08:00
Dan Albert
bac7bb5c16 Fix a couple sign-comparison warnings.
Bug: http://b/26523949
Change-Id: Id33146b5544147945fee3f14f7f72f39bae449f6
2016-01-15 12:18:14 -08:00
Elliott Hughes
f2584be414 Rename base/ to android-base/.
Bug: http://b/26023797
Change-Id: Ie6c63bf86bed05faab87d290de6f34d9af3532a8
2015-12-07 14:31:53 -08:00
Elliott Hughes
4f71319df0 Track rename of base/ to android-base/.
Change-Id: Idf9444fece4aa89c93e15640de59a91f6e758ccf
2015-12-04 22:00:26 -08:00
Elliott Hughes
7f24c45b7d Add a symlink android-base/ pointing to base/.
This lets us move things over piece by piece without breaking anything.

Change-Id: I06fc29572f63c4af9675888987acdcdea086711d
2015-12-04 15:18:27 -08:00
Casey Dahlin
918b9e8dc6 Introduce unique_fd
unique_fds are wrappers for integer file descriptors that automatically
close when they go out of scope. They are movable but not copyable and
generally mimic the semantics of std::unique_ptr

Change-Id: I0657b848b6536d5ad9fc06686e240ea5c387b0ac
Test: Considerable exercise in new AIDL integration tests
Bug: None
Signed-off-by: Casey Dahlin <sadmac@google.com>
2015-11-18 12:01:24 -08:00
Spencer Low
d21dc825bb adb: win32: remove widen()/narrow() in favor of UTF8ToWide()/WideToUTF8()
Now that we have a more standardized API (also available in Chromium),
switch to it. Another benefit is real error handling instead of just
killing the process on invalid Unicode.

Make UTF8ToWide()/WideToUTF8() set errno to EILSEQ on bad input. This is
the same error code that wcsrtombs(3) uses.

Update the unittest to check for EILSEQ.

Change-Id: Ie92acf74d37adaea116cf610c1bf8cd433741e16
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-11-12 17:13:08 -08:00
Josh Gao
26f2e1fd4f Merge changes Ic124ecb9,I94de55d2
* changes:
  libbase: remove exit-time destructors.
  adb: remove exit-time destructors.
2015-11-12 22:50:03 +00:00
Josh Gao
7df6b5fc79 libbase: remove exit-time destructors.
Removed for the same reason as the adb exit-time destructors.

Bug: http://b/23384853
Change-Id: Ic124ecb9df132b850a3855e207baffec926dde29
2015-11-12 11:54:47 -08:00
Elliott Hughes
c1fd492ac5 Revert "Revert "adb/base: fix adb push of Unicode filenames on Win32""
This reverts commit cc8cd59456.

With the dependency on libcutils (for gettid for non-bionic) removed,
this no longer breaks the build.

Change-Id: I645bd6876e2502ddc1535b69af1e645c0df9d178
2015-11-11 18:23:00 -08:00
Elliott Hughes
cc8cd59456 Revert "adb/base: fix adb push of Unicode filenames on Win32"
This reverts commit ac9514a452.

The new gettid dependency caused other breakage.

Change-Id: I74a75e40c30a45beb275f9dd38eb5c7beac15fbd
2015-11-11 18:01:12 +00:00
Spencer Low
ac9514a452 adb/base: fix adb push of Unicode filenames on Win32
ae5a6c06cd made adb push use
android::base::ReadFileToString() for small files, but that API did not
support UTF-8 filenames on Windows, until this fix which does the
following:

- Add android::base::{WideToUTF8,UTF8ToWide}() which are only available
  on Windows. The signatures are based on Chromium's APIs of the same
  name.

- Add the namespace android::base::utf8 which has versions of APIs that
  take UTF-8 strings. To use this, make sure your code is in a namespace
  and then do "using namespace android::base::utf8;". On Windows, this will
  make calls to open() call android::base::utf8::open(), and on other
  platforms, it will just call the regular ::open().

- Make ReadFileToString() and WriteStringToFile() use utf8::open() and
  utf8::unlink().

- Adapt unittests from Chromium.

- fastboot needs to link with libcutils because it links with libbase
  which depends on libcutils for gettid() for logging.

Change-Id: I1aeac40ff358331d7a1ff457ce894bfb17863904
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-11-10 15:48:54 -08:00
Spencer Low
363af568b8 adb/base: minor compiler portability improvements
I've been using these changes to compile with Visual Studio.

- GetFileBasename(): __FILE__ uses \ with Visual Studio.

- adb_trace.cpp: Apparently VS needs an ampersand before the function name.

- "expr1 ? : expr2" is a GCC extension.

- <algorithm> contains std::min().

- seekdir can't always be #define'd because some headers have members
  named seekdir.

- adb_utils.cpp: Not really a compiler issue, just a random fix:
  0x7F/DEL is not printable.

Change-Id: I0dfb634f1ba4ccbc0d1b9f71b00e838fbebb3b41
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-11-09 10:22:13 -08:00
Casey Dahlin
46776e7423 Merge "Make Join support string delimiters" 2015-11-02 20:28:09 +00:00
Casey Dahlin
5345f1df0d Make Join support string delimiters
We've needed this several times in the past.

Change-Id: I7324e8083fe2ff1aa0bf392a8c124fc2f3bb26e2
Test: Full android build
Signed-off-by: Casey Dahlin <sadmac@google.com>
2015-11-02 11:04:34 -08:00
Elliott Hughes
3ab05869d8 Fix ParseInt/ParseUint to handle explicit "0x" hex.
Also improve fastboot error reporting around max-download-size.

Change-Id: Ic3aec9460de01e5264a2803a0a6be3706d73026b
2015-11-02 09:01:53 -08:00
Elliott Hughes
c96de0d36e Fix lseek argument order.
Change-Id: I12feed2de8a4e0782f90609254a3e2ec66d7d98e
2015-10-20 13:18:22 -07:00
Spencer Low
765ae6bcfc base logging: fix errno restoring, severity conditionality, dangling ifs
Fix LOG() to properly save and restore errno. Test this properly.

Only do logging if severity is >= the minimum.

Fix dangling if statements in CHECK(), CHECK_STR{EQ,NE}(). Test this
properly.

Fix base logging tests on Windows. All libbase_tests now pass on
Windows.

Change place to lock, so the lock can protect logging of all data in
LogMessage.

Change-Id: I7ff531c67ae10a99ef0a2bbfe279aa77282d5ae9
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-09-21 12:46:12 -07:00
Spencer Low
b2d4949cee libbase_test: get it building for Windows
Add to whitelist.

For some reason, when compiling, parseint_test.cpp would encounter
errors like the following:

host cross C++: host_cross_libbase_test <= system/core/base/parseint_test.cpp
In file included from external/gtest/include/gtest/gtest.h:1929:0,
                 from system/core/base/parseint_test.cpp:19:
system/core/base/parseint_test.cpp: In member function ‘virtual void parseint_signed_smoke_Test::TestBody()’:
external/gtest/include/gtest/internal/gtest-internal.h:133:55: error: converting ‘false’ to pointer type for argument 1 of ‘char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)’ [-Werror=conversion-null]
     (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1)
                                                       ^
external/gtest/include/gtest/gtest_pred_impl.h:77:52: note: in definition of macro ‘GTEST_ASSERT_’
   if (const ::testing::AssertionResult gtest_ar = (expression)) \
                                                    ^
external/gtest/include/gtest/gtest_pred_impl.h:166:3: note: in expansion of macro ‘GTEST_PRED_FORMAT2_’
   GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
   ^
external/gtest/include/gtest/gtest.h:1993:3: note: in expansion of macro ‘ASSERT_PRED_FORMAT2’
   ASSERT_PRED_FORMAT2(::testing::internal:: \
   ^
external/gtest/include/gtest/gtest.h:1994:32: note: in expansion of macro ‘GTEST_IS_NULL_LITERAL_’
                       EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
                                ^
external/gtest/include/gtest/gtest.h:2011:32: note: in expansion of macro ‘GTEST_ASSERT_EQ’
 # define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
                                ^
system/core/base/parseint_test.cpp:23:3: note: in expansion of macro ‘ASSERT_EQ’
   ASSERT_EQ(false, android::base::ParseInt("x", &i));
   ^

For whatever reason, the gcc for Windows isn't handling the template
metaprogramming correctly, so to work-around the issue, I
search-and-replaced "ASSERT_EQ(false, " to "ASSERT_FALSE(" and
"ASSERT_EQ(true, " to "ASSERT_TRUE(" and that seems to compile just fine
for Linux and Windows (and the tests pass on both platforms).

Change-Id: I05132909d1f4b18afff23139652a218649689f2d
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-09-11 20:01:29 -07:00
Dan Albert
933f4fd413 Merge "Ensure that libbase and liblog can be built for Windows." 2015-09-11 20:47:07 +00:00
Stephen Hines
b0e4f08226 Ensure that libbase and liblog can be built for Windows.
Change-Id: If4adf1e2bd7ec36a7f02ae2e263d2db5187c6e7b
2015-09-11 11:39:16 -07:00
Elliott Hughes
afe151fb02 Add ParseInt (and ParseUint).
strtol and family are hard to use correctly, and most callers don't
even try.

Change-Id: I2833622a92cccd4662c0c5bdbbef5eeb4e496914
2015-09-04 16:32:00 -07:00
Dan Willemsen
87a419c8b1 Remove USE_MINGW/CYGWIN; Whitelist windows modules
CYGWIN is not supported, USE_MINGW and HOST_OS==windows are being
replaced with LOCAL_..._windows variables.

Bug: 23566667
Change-Id: I3e4a1e4097dc994cf5abdce6939e83a91758fd75
2015-09-02 17:10:35 -07:00
Spencer Low
2fbeb0cc71 adb/base win32 tests: fix comment and open() flags
Match base's use of O_BINARY.

Change-Id: I930b5c8fddde20966580069f2e681b99cb26f1a3
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-09-01 14:57:58 -07:00
Elliott Hughes
470d79a09c Use O_BINARY in base/file for Windows.
This matches the behavior of the google3/Chrome APIs. It's probably what you
want in all cases except where you plan on calling Split(content, "\n"), but
we should probably have something like simpleperf's LineReader for that
anyway.

Change-Id: I1a128ed8c328bc95b0b2ef4068a65a8562721418
2015-09-01 13:35:44 -07:00
Elliott Hughes
2e5ae0044a Fix the Mac libbase build.
Change-Id: I34224fa66850915ef47c88ef4c79efbc53f3f38e
2015-08-13 20:09:29 -07:00
Spencer Low
bdab59a861 libbase: logging fixes
Win32:

- getprogname(): call basename() which is available in mingw's crt.
  Don't potentially go recursive with DCHECK_GT().

- Use Win32 critical section instead of mutex.

Other:

- Change log_characters check to compile-time.

- Fix code that gets the basename of __FILE__. The previous code was not
  setting _file, so it didn't work.

- Save and restore errno for LOG calls. Inspired by similar Chromium code.

Change-Id: Ie7bb700918be726fa81d60177d1894d2daeff296
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-08-13 14:08:31 -07:00
Spencer Low
cbf26b76c7 win32: adb_test/libbase_test fixes
- My recent change with -DUNICODE=1 required changing
   GetProfilesDirectory() to GetProfilesDirectoryA() for the ANSI version
   of the API.

 - enh's edit to my previous change deleted a test that used
   /proc/version, but I think another test was missed. Merge that test into
   another.

Change-Id: Ic748549848e7be922bcbf218d5b0c3fca2a90704
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-08-06 18:09:32 -07:00
Spencer Low
cf168a82e9 adb_test/libbase_test: win32: get some tests working
adb_test:

* Fix adb_utils directory_exists test for Windows. The test actually
fails because directory_exists() is not aware of junctions or symlinks,
but I'm not really sure if that is a bad thing (since these are rare on
Windows to begin with).

* Fix crash during transport tests due to mutex not being initialized.

* io tests fail for various reasons (see adb_io_test.cpp for more info).

libbase_test:

* Get it building on Win32 by implementing mkstemp() and mkdtemp().

* Run StringPrintf %z test on Windows because it passes because we build
with __USE_MINGW_ANSI_STDIO which implements %z.

* I didn't fixup the logging tests: some logging tests fail because when
abort() is called on Windows, by default it pops up UI asking whether a
crash dump should be sent to Microsoft. To some degree this makes sense,
as I think LOG(FATAL) does crash dumping in Chromium. This should be
revisited in the future.

Change-Id: Iaa2433e5294ff162e0b2aa9fe6e4ec09a6893f7a
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-08-03 12:44:43 -07:00
Spencer Low
40d0c7aead libbase_test: win32: get some tests working
* Get it building on Win32 by implementing mkstemp() and mkdtemp().

* Run StringPrintf %z test on Windows because it passes because we build
with __USE_MINGW_ANSI_STDIO which implements %z.

Change-Id: Ia01f94e8258503381a1df6d3da6e40de59e57125
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-08-03 10:54:17 -07:00
Alex Vallée
47d67c96ec Write mkdirs in more idiomatic C++ style.
~ Rewrote mkdirs to be in C++ style.
~ Replaced adb_dir{start,stop} with std::string params and (r)find.
+ Added test for mkdirs.

Also make base/test_utils.h public and support temporary directories
as well as files.

Change-Id: I6fcbdc5e0099f3359d3aac6b00c436f250ca1329
2015-07-30 15:08:53 -07:00
Dan Albert
286bb6ddbd Revert "Turn on -Wformat-nonliteral."
One of my build aliases doesn't play nice with USE_MINGW=1, so my build lied to me. Will revert until I fix it up.

This reverts commit 459df8f3a1.

Change-Id: I7905c5ae5ee85fb2d228ce63d81c79f140998c18
2015-07-09 20:35:09 +00:00
Dan Albert
459df8f3a1 Turn on -Wformat-nonliteral.
Apparently there are two classes of this warning in clang.
-Wformat-security is only emitted for cases of
`func(nonliteral_fmt_string)` (no args), and -Wformat-nonliteral is
emitted for cases *with* arguments. For whatever reason, the latter
isn't included in -Wextra and must be manually enabled.

To make this more easily portable to Windows, move the existing
gnu_printf/__printf__ decision into base/macros.h as ATTRIBUTE_FORMAT.

Change-Id: I3b0990e1d1f0a2e9c13b32f5cd60478946cb5fc6
2015-07-09 10:47:24 -07:00
Dan Albert
e0da8a1d37 Generalize Join to work for any container/element.
This is more scalable than explicitly instantiating templates for the
cross product of containers and element types.

Specifically I'm adding this so I can join an unordered_set in adb.

Change-Id: I0055f3390a0ff26a886a0d41bbf0d4fe3d210f9c
2015-05-22 10:07:06 -07:00
Dan Albert
b7930843d3 Merge "adb / libbase: clean up NOGDI and evil ERROR macro" 2015-05-20 19:45:49 +00:00
Spencer Low
ac3f7d9a78 adb / libbase: clean up NOGDI and evil ERROR macro
Instead of defining and undefining NOGDI:

1. Always #include "base/logging.h" after #include <windows.h>.
Unfortunately, I could not find an easy way to give the user a
warning/error if they include in the wrong order.

2. base/logging.h does #undef ERROR to undefine the evil ERROR macro
that is from another era and probably a bad idea to begin with.

Change-Id: I995d89620611e849af9d7ec47eb55fc0512377f2
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-05-20 12:25:19 -07:00
Nick Kralevich
95db36e128 Don't use TEMP_FAILURE_RETRY on close()
See https://lkml.org/lkml/2005/9/10/129 for details.

Bug: 20501816
Change-Id: I38bf5052f44034c6f866d10d7d07187f0053a7a1
2015-05-20 09:02:29 -07:00
Spencer Low
6001c87cbc adb: win32: fix StringPrintf format string checking of %zd and PRIu64
At runtime, vsnprintf (and android::base::StringPrintf which calls it)
call a mingw version of vsnprintf, not the vsnprintf from MSVCRT.DLL.
The mingw version properly understands %zd and PRIu64 (the latter,
provided that you #include <inttypes.h>).

The problem was that android::base::StringPrintf was causing
compile-time errors saying that %zd and PRIu64 were not recognized. It
seems that this was because the attribute on the function prototypes
specified `printf' instead of `gnu_printf'. Once that was fixed to match
vsnprintf's attribute, the warnings went away.

This uses similar preprocessor techniques as <android/log.h>.

Also restore a %zd usage to avoid a static_cast<>, and make
print_transfer_progress()'s format string compile-time checkable (and
tweak some types and %llu => PRIu64).

Change-Id: I80b31b9994858a28cb7c6847143b86108b8ab842
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-05-13 19:30:30 -07:00
Spencer Low
142ec75cf8 adb: win32: fix adb emu command
The adb emu command was never working because the socket connection to
the emulator was closed without reading all of the data that the
emulator sent. On Windows, this caused the emulator's recv() call to
error-out, so it never got the command that was sent.

Before settling on this fix, I also experimented changing the arguments
to the socket shutdown() call and that didn't seem to help. I also tried
removing the call to shutdown() and that didn't help. So that should
rule out shutdown() as the problem. One experiment that helped was
delaying before calling adb_close(), but that is of course fragile and
doesn't address the real issue, which is not closing the socket until
the commands have been read.

https://code.google.com/p/android/issues/detail?id=21021

Change-Id: I8fa4d740a2faa2c9922ec50792e16564a94f6eed
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-05-06 18:54:08 -07:00
Dan Albert
ea41c213be Add additional shielding against the ERROR macro.
Including the logging header with ERROR defined will always be a
problem, so check for it explicitly.

Move the NOGDI define from logging.cpp to logging.h since the standard
library headers might be including windows.h, pulling in ERROR.

Change-Id: Ib426973d2f1840710c0bf0e0cfb2420d0d322e27
2015-05-04 16:40:38 -07:00
Colin Cross
56b37345d9 Fix comparison between signed and unsigned error on darwin
mode_t is a uint16_t on darwin, which causes
sb.st_mode & ~S_IFMT
to produce an int when the uint16_t is promoted for the operator.
Cast to unsigned int before comparing against 0660U.

Change-Id: Ib1439c08d9e2b297eeeba701891508d269c19a3d
2015-04-30 16:58:26 -07:00
Dan Albert
5c19040b06 Support base::logging on Windows.
libc++ doesn't support std::mutex and friends for Windows yet, so we
just use a compatibility wrapper for now.

Change-Id: I2413d4c089e7d0fb232444043c6b772153035dab
2015-04-29 18:01:53 -07:00
Dan Albert
0c4b3a319d Get libbase tests working on Windows.
Tests using files from /proc still fail on Windows (obviously), but
all tests are passing when run in Wine.

Change-Id: Ie4c3ba65b642202f8fcaec73332a53bee6115fba
2015-04-29 17:11:28 -07:00
Dan Albert
850188fc04 Print strerror instead of errno in tests.
Change-Id: Ibfab1b7cd439fdb5ae19855cc700613c00d4aff8
2015-04-29 17:10:49 -07:00
Elliott Hughes
8d5fa6da44 Remove strtok from adb.
Also fix android::base::Split to behave like Java, Python, and google3.

Change-Id: Ifbffd4e92950a79e7aea5d153c95fe0980648417
2015-04-27 19:42:20 -07:00
Elliott Hughes
56085edbf8 Add ReadFully and WriteFully to libbase.
Change-Id: I6b7aa2a93398e7acdd1d74c71d9abed08a72b3c4
2015-04-24 21:57:16 -07:00
Elliott Hughes
1daf86aa20 Fix comment typo.
Change-Id: I2d7082c44123e90d74b2669ab29d787b9aa64863
2015-04-17 17:08:16 -07:00
Dan Albert
cf9c855e5b Add base/memory.h.
Right now this only includes an API for unaligned reads/writes.

Change-Id: Ieb42498aa17cbd1035b66c51bd1c4f16fa2acfdb
2015-04-09 17:00:14 -07:00
Dan Albert
7a87d05974 Cleanup base/logging.
Some of this code was unused, most didn't need to be exposed, and we
can just use basename(3).

Also use a better default program name than "unknown".

Change-Id: I62d990f64e4fd0c16aa4b7e907dd06e4f26ddcdd
2015-04-03 16:49:55 -07:00
Dan Albert
b547c85b5b Support arbitrary loggers.
While the defaults (logd or stderr) make sense for most use cases,
there are places that can only log to the kernel, or need to log to a
file, etc.

Allow the user to pass in an arbitrary logging object, and provide
LogdLogger and StderrLogger as defaults.

Change-Id: I62368acc795ff313242bb205d65017404bf64e88
2015-04-03 16:22:39 -07:00
Dan Albert
0c055863eb Support logging to other log buffers.
LOGTO(dest, severity) and PLOGTO(dest, severity) log to other log
buffers. For example, `LOGTO(SYSTEM, FATAL) << "Foobar";`.

Change-Id: Id1ca1c8fdae72d69b73945ae9b006525d0be1582
2015-04-03 10:14:48 -07:00
Dan Albert
8ea5dd8c6e Merge "Remove LogMessage::LogLineLowStack." 2015-04-03 16:52:02 +00:00
Dan Albert
0cc351b1a7 Remove LogMessage::LogLineLowStack.
This was ported over from ART, but even they only use it in a single
place.

Change-Id: Ia34dc54b56c764ede79b2957bf3dc8df0f1323ee
2015-04-02 18:43:32 -07:00
Dan Albert
da926f0350 Don't show lint errors for rvalue references.
Change-Id: Ic936c9e3778303d1d26813b844ccd3bb26701550
2015-04-02 18:38:01 -07:00
Dan Albert
b2326bd56c Enable building libbase on Windows.
We have to exclude the logging facilities for now (since we don't have
a std::mutex on Windows), but there's plenty else in here that is
worth having.

Change-Id: I6d1369e34e08ea2e88a0b1130c4462e5d35d99e2
2015-03-30 10:30:42 -07:00
Dan Albert
42f1192273 Merge "Pull in Windows compatibility header." 2015-03-27 06:35:54 +00:00
Dan Albert
94d1360f7e Pull in Windows compatibility header.
Needed for O_CLOEXEC, O_NOFOLLOW, and DEFFILEMODE.

Change-Id: Id6c0465a6559c30ac8c085c28be0d47c9738f02a
2015-03-26 23:33:28 -07:00
Dan Albert
4b3f533be9 Include what we use.
Change-Id: If510431d3d445de94f781b4fdec2e1b445f7c294
2015-03-26 23:23:43 -07:00
Dan Albert
7dfb61dcdc Move gettid() into libcutils.
Change-Id: Ic8a15036833e6d129b7998d954b804be391de399
2015-03-23 13:01:21 -07:00
Dan Albert
47328c96d9 Update string Split API.
Return a new vector rather than appending to the parameter.

Delimiters are also a string rather than a character. Split on any
character in the string.

Change-Id: I039b332ace5578590df9e7ca0e8fa3db28db30a3
2015-03-23 10:23:11 -07:00
Dan Albert
58310b49fc Add google3 style logging to libbase.
ART already had a flavor of this, but it was specialized for their use
case a bit.

Note that the logging.* tests are currently disabled for the device
because there is no good way to capture the output of liblog. We can
make something that will execute logcat and then then scan the output,
but that's messy. Since we know it at least works on the host, we can
add better device tests later.

Change-Id: I47acd87a3312c0a5285b03f9c8dadef0c669f06a
2015-03-20 14:04:35 -07:00
Dan Albert
9c5c08be37 Use mingw on Windows.
LOCAL_CLANG := true is a no-op on Linux/Darwin host builds, but
apparently moves Windows binaries from mingw to clang, which is
completely untested.

Change-Id: Ibbc468d4a19a9e36bbcb93aa030fcc771af020ba
2015-03-19 22:44:50 -07:00
Dan Albert
0f1e54491c Add common string utilities to libbase.
These are useful outside of ART. Nothing changed (aside from fixing
Trim to not segfault on empty strings), so ART should be able to move
to using these.

Change-Id: Id026ebffe8d31f784a91834786ab189680b13a0f
2015-03-16 20:03:03 -07:00
Dan Albert
76d9cad62c Revert "Revert "Add commonly used C++ macros to libbase.""
This reverts commit 0722bae789.
2015-03-16 10:09:07 -07:00
Dan Albert
c007bc3856 Revert "Revert "Create libbase.""
This reverts commit a7870d8816.
2015-03-16 10:08:46 -07:00
Nicolas Geoffray
a7870d8816 Revert "Create libbase."
Breaks internal master.

This reverts commit 98ff77204c.

Change-Id: I18dc6021cb43efff8aa88486c2d980dc2b8eedba
2015-03-16 11:07:29 +00:00
Nicolas Geoffray
0722bae789 Revert "Add commonly used C++ macros to libbase."
Breaks master build.

This reverts commit 7fbdaddfac.

Change-Id: I53d090f7dee8ed30fc49d908939153996cdb2298
2015-03-16 10:46:43 +00:00
Dan Albert
7fbdaddfac Add commonly used C++ macros to libbase.
Change-Id: I74f5dbfc4d99f7e78212a72540e538c1a737e224
2015-03-14 16:36:18 -07:00
Dan Albert
98ff77204c Create libbase.
Move StringPrintf and the string based file I/O from libutils to
libbase.

Change-Id: I0297a6063874b9d92100e0dd5123fddfbda932fe
2015-03-14 16:36:18 -07:00