Commit graph

43 commits

Author SHA1 Message Date
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