blob: 41c7015090432bee586a406822251058f809b4a6 [file] [log] [blame]
Martin Stjernholmd4aba912022-01-25 21:05:47 +00001/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "dex2oat_environment_test.h"
18
19namespace art {
20
21class Dex2oatCtsTest : public Dex2oatEnvironmentTest {};
22
23// Run dex2oat with --enable-palette-compilation-hooks to force calls to
24// PaletteNotify{Start,End}Dex2oatCompilation.
25TEST_F(Dex2oatCtsTest, CompilationHooks) {
26 const std::string dex_location = GetTestDexFileName("Main");
27 const std::string oat_location = GetScratchDir() + "/base.oat";
28 const std::string vdex_location = GetScratchDir() + "/base.vdex";
29
30 std::vector<std::string> args;
31 args.emplace_back("--dex-file=" + dex_location);
32
33 std::unique_ptr<File> oat_file(OS::CreateEmptyFile(oat_location.c_str()));
34 ASSERT_NE(oat_file, nullptr) << oat_location;
35 args.emplace_back("--oat-fd=" + std::to_string(oat_file->Fd()));
36 args.emplace_back("--oat-location=" + oat_location);
37
38 std::unique_ptr<File> vdex_file(OS::CreateEmptyFile(vdex_location.c_str()));
39 ASSERT_NE(vdex_file, nullptr) << vdex_location;
40 args.emplace_back("--output-vdex-fd=" + std::to_string(vdex_file->Fd()));
41
42 args.emplace_back("--force-palette-compilation-hooks");
43
44 std::string output = "";
45 std::string error_msg;
46 int res = Dex2Oat(args, &output, &error_msg);
47 EXPECT_EQ(res, 0) << error_msg;
48 EXPECT_EQ(oat_file->FlushCloseOrErase(), 0);
49 EXPECT_EQ(vdex_file->FlushCloseOrErase(), 0);
50}
51
52} // namespace art