89 lines
2.2 KiB
C
Raw Normal View History

Add a new build, install, test development (bit) tool This is a cleaned up version of a utility that I've had sitting around for a while. The bit tool can run an android platform build, then sync or install the outputs of that, and then run instrumentation tests. It's better than what we usually do: make && adb shell stop && adb sync system && adb shell start Here's the help text: usage: bit OPTIONS PATTERN Build, sync and test android code. The -b -i and -t options allow you to specify which phases you want to run. If none of those options are given, then all phases are run. If any of these options are provided then only the listed phases are run. OPTIONS -b Run a build -i Install the targets -t Run the tests PATTERN One or more targets to build, install and test. The target names are the names that appear in the LOCAL_MODULE or LOCAL_PACKAGE_NAME variables in Android.mk or Android.bp files. Building and installing ----------------------- The modules specified will be built and then installed. If the files are on the system partition, they will be synced and the attached device rebooted. If they are APKs that aren't on the system partition they are installed with adb install. For example: bit framework Builds framework.jar, syncs the system partition and reboots. bit SystemUI Builds SystemUI.apk, syncs the system partition and reboots. bit CtsProtoTestCases Builds this CTS apk, adb installs it, but does not run any tests. Running Unit Tests ------------------ To run a unit test, list the test class names and optionally the test method after the module. For example: bit CtsProtoTestCases:* Builds this CTS apk, adb installs it, and runs all the tests contained in that apk. bit framework CtsProtoTestCases:* Builds the framework and the apk, syncs and reboots, then adb installs CtsProtoTestCases.apk, and runs all tests contained in that apk. bit CtsProtoTestCases:.ProtoOutputStreamBoolTest bit CtsProtoTestCases:android.util.proto.cts.ProtoOutputStreamBoolTest Builds and installs CtsProtoTestCases.apk, and runs all the tests in the ProtoOutputStreamBoolTest class. bit CtsProtoTestCases:.ProtoOutputStreamBoolTest\#testWrite Builds and installs CtsProtoTestCases.apk, and runs the testWrite test method on that class. bit CtsProtoTestCases:.ProtoOutputStreamBoolTest\#testWrite,.ProtoOutputStreamBoolTest\#testRepeated Builds and installs CtsProtoTestCases.apk, and runs the testWrite and testRepeated test methods on that class. Launching an Activity --------------------- To launch an activity, specify the activity class name after the module name. For example: bit StatusBarTest:NotificationBuilderTest bit StatusBarTest:.NotificationBuilderTest bit StatusBarTest:com.android.statusbartest.NotificationBuilderTest Builds and installs StatusBarTest.apk, launches the com.android.statusbartest/.NotificationBuilderTest activity. Change-Id: I9cff7a23852fa1a67369e7807f7ae9f6e45d6131 Test: none
2016-10-19 17:03:06 -07:00
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef UTIL_H
#define UTIL_H
#include <map>
#include <string>
#include <vector>
using namespace std;
struct FileInfo
{
bool exists;
time_t mtime;
time_t ctime;
off_t size;
FileInfo();
FileInfo(const FileInfo& that);
explicit FileInfo(const string& filename);
~FileInfo();
bool operator==(const FileInfo& that) const;
bool operator!=(const FileInfo& that) const;
};
/**
* Record for a file that we are watching
*/
struct TrackedFile {
string filename;
FileInfo fileInfo;
TrackedFile();
TrackedFile(const TrackedFile& that);
explicit TrackedFile(const string& filename);
~TrackedFile();
// Returns if the file has changed. If it doesn't currently exist, returns true.
bool HasChanged() const;
};
/**
* Get FileInfo structures recursively for all the files and symlinks in a directory.
* Does not traverse symlinks, but it does record them.
*/
void get_directory_contents(const string& dir, map<string,FileInfo>* results);
bool directory_contents_differ(const map<string,FileInfo>& before,
const map<string,FileInfo>& after);
string escape_quotes(const char* str);
string escape_for_commandline(const char* str);
string trim(const string& trim);
bool starts_with(const string& str, const string& prefix);
bool ends_with(const string& str, const string& suffix);
void split_lines(vector<string>* result, const string& str);
string read_file(const string& filename);
bool is_executable(const string& filename);
string dirname(const string& filename);
string leafname(const string& filename);
Add a new build, install, test development (bit) tool This is a cleaned up version of a utility that I've had sitting around for a while. The bit tool can run an android platform build, then sync or install the outputs of that, and then run instrumentation tests. It's better than what we usually do: make && adb shell stop && adb sync system && adb shell start Here's the help text: usage: bit OPTIONS PATTERN Build, sync and test android code. The -b -i and -t options allow you to specify which phases you want to run. If none of those options are given, then all phases are run. If any of these options are provided then only the listed phases are run. OPTIONS -b Run a build -i Install the targets -t Run the tests PATTERN One or more targets to build, install and test. The target names are the names that appear in the LOCAL_MODULE or LOCAL_PACKAGE_NAME variables in Android.mk or Android.bp files. Building and installing ----------------------- The modules specified will be built and then installed. If the files are on the system partition, they will be synced and the attached device rebooted. If they are APKs that aren't on the system partition they are installed with adb install. For example: bit framework Builds framework.jar, syncs the system partition and reboots. bit SystemUI Builds SystemUI.apk, syncs the system partition and reboots. bit CtsProtoTestCases Builds this CTS apk, adb installs it, but does not run any tests. Running Unit Tests ------------------ To run a unit test, list the test class names and optionally the test method after the module. For example: bit CtsProtoTestCases:* Builds this CTS apk, adb installs it, and runs all the tests contained in that apk. bit framework CtsProtoTestCases:* Builds the framework and the apk, syncs and reboots, then adb installs CtsProtoTestCases.apk, and runs all tests contained in that apk. bit CtsProtoTestCases:.ProtoOutputStreamBoolTest bit CtsProtoTestCases:android.util.proto.cts.ProtoOutputStreamBoolTest Builds and installs CtsProtoTestCases.apk, and runs all the tests in the ProtoOutputStreamBoolTest class. bit CtsProtoTestCases:.ProtoOutputStreamBoolTest\#testWrite Builds and installs CtsProtoTestCases.apk, and runs the testWrite test method on that class. bit CtsProtoTestCases:.ProtoOutputStreamBoolTest\#testWrite,.ProtoOutputStreamBoolTest\#testRepeated Builds and installs CtsProtoTestCases.apk, and runs the testWrite and testRepeated test methods on that class. Launching an Activity --------------------- To launch an activity, specify the activity class name after the module name. For example: bit StatusBarTest:NotificationBuilderTest bit StatusBarTest:.NotificationBuilderTest bit StatusBarTest:com.android.statusbartest.NotificationBuilderTest Builds and installs StatusBarTest.apk, launches the com.android.statusbartest/.NotificationBuilderTest activity. Change-Id: I9cff7a23852fa1a67369e7807f7ae9f6e45d6131 Test: none
2016-10-19 17:03:06 -07:00
#endif // UTIL_H