2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <gtest/gtest.h>
24 TEST(ActionTest, malloc) {
25 uint8_t memory[Action::MaxActionSize()];
26 const char* line = "1024";
27 Action* action = Action::CreateAction(0x1234, "malloc", line, memory);
28 ASSERT_TRUE(action != NULL);
29 ASSERT_FALSE(action->DoesFree());
30 ASSERT_FALSE(action->EndThread());
33 action->Execute(&pointers);
34 void* pointer = pointers.Remove(0x1234);
35 ASSERT_TRUE(pointer != nullptr);
39 TEST(ActionTest, malloc_malformed) {
41 const char* line = "";
42 Action* action = Action::CreateAction(0x1234, "malloc", line, memory);
43 ASSERT_FALSE(action != NULL);
46 TEST(ActionTest, free) {
48 const char* line = "";
49 Action* action = Action::CreateAction(0x1234, "free", line, memory);
50 ASSERT_TRUE(action != NULL);
51 ASSERT_TRUE(action->DoesFree());
52 ASSERT_FALSE(action->EndThread());
55 pointers.Add(0x1234, malloc(10));
56 action->Execute(&pointers);
59 TEST(ActionTest, calloc) {
61 const char* line = "100 10";
62 Action* action = Action::CreateAction(0x1234, "calloc", line, memory);
63 ASSERT_TRUE(action != NULL);
64 ASSERT_FALSE(action->DoesFree());
65 ASSERT_FALSE(action->EndThread());
68 action->Execute(&pointers);
69 void* pointer = pointers.Remove(0x1234);
70 ASSERT_TRUE(pointer != nullptr);
74 TEST(ActionTest, free_zero) {
76 const char* line = "";
77 Action* action = Action::CreateAction(0, "free", line, memory);
78 ASSERT_TRUE(action != NULL);
79 ASSERT_FALSE(action->DoesFree());
80 ASSERT_FALSE(action->EndThread());
82 action->Execute(nullptr);
85 TEST(ActionTest, calloc_malformed) {
87 const char* line1 = "100";
88 Action* action = Action::CreateAction(0x1234, "calloc", line1, memory);
89 ASSERT_FALSE(action != NULL);
91 const char* line2 = "";
92 action = Action::CreateAction(0x1234, "calloc", line2, memory);
93 ASSERT_FALSE(action != NULL);
96 TEST(ActionTest, realloc) {
98 const char* line = "0xabcd 100";
99 Action* action = Action::CreateAction(0x1234, "realloc", line, memory);
100 ASSERT_TRUE(action != NULL);
101 ASSERT_TRUE(action->DoesFree());
102 ASSERT_FALSE(action->EndThread());
104 Pointers pointers(1);
105 pointers.Add(0xabcd, malloc(10));
106 action->Execute(&pointers);
107 void* pointer = pointers.Remove(0x1234);
108 ASSERT_TRUE(pointer != nullptr);
111 const char* null_line = "0x0 100";
112 action = Action::CreateAction(0x1234, "realloc", null_line, memory);
113 ASSERT_FALSE(action->DoesFree());
114 ASSERT_FALSE(action->EndThread());
116 action->Execute(&pointers);
117 pointer = pointers.Remove(0x1234);
118 ASSERT_TRUE(pointer != nullptr);
122 TEST(ActionTest, realloc_malformed) {
124 const char* line1 = "0x100";
125 Action* action = Action::CreateAction(0x1234, "realloc", line1, memory);
126 ASSERT_FALSE(action != NULL);
128 const char* line2 = "";
129 action = Action::CreateAction(0x1234, "realloc", line2, memory);
130 ASSERT_FALSE(action != NULL);
133 TEST(ActionTest, memalign) {
135 const char* line = "16 300";
136 Action* action = Action::CreateAction(0x1234, "memalign", line, memory);
137 ASSERT_TRUE(action != NULL);
138 ASSERT_FALSE(action->DoesFree());
139 ASSERT_FALSE(action->EndThread());
141 Pointers pointers(1);
142 action->Execute(&pointers);
143 void* pointer = pointers.Remove(0x1234);
144 ASSERT_TRUE(pointer != nullptr);
148 TEST(ActionTest, memalign_malformed) {
150 const char* line1 = "100";
151 Action* action = Action::CreateAction(0x1234, "memalign", line1, memory);
152 ASSERT_FALSE(action != NULL);
154 const char* line2 = "";
155 action = Action::CreateAction(0x1234, "memalign", line2, memory);
156 ASSERT_FALSE(action != NULL);
159 TEST(ActionTest, endthread) {
161 const char* line = "";
162 Action* action = Action::CreateAction(0x0, "thread_done", line, memory);
163 ASSERT_TRUE(action != NULL);
164 ASSERT_FALSE(action->DoesFree());
165 ASSERT_TRUE(action->EndThread());
167 action->Execute(nullptr);