[test determinator] Match Objective-C methods, add test

Summary: For Objective-C methods we match the mangled names (the field is name in the profiler samples).

Reviewed By: skcho

Differential Revision: D17952552

fbshipit-source-id: 308d415f6
master
Dulma Churchill 5 years ago committed by Facebook Github Bot
parent 43990ee60b
commit 0e116c5557

@ -206,6 +206,8 @@ let match_profiler_samples_affected_methods native_symbols affected_methods =
match affected_method with match affected_method with
| Some (ClangProc.CFunction {name}) -> | Some (ClangProc.CFunction {name}) ->
String.equal name native_symbol.Clang_profiler_samples_t.name String.equal name native_symbol.Clang_profiler_samples_t.name
| Some (ClangProc.ObjcMethod {mangled_name}) ->
String.equal mangled_name native_symbol.Clang_profiler_samples_t.name
| _ -> | _ ->
false false
(* TODO: deal with mangled names, other method kinds *) (* TODO: deal with mangled names, other method kinds *)

@ -7,8 +7,10 @@
TESTS_DIR = ../.. TESTS_DIR = ../..
include $(TESTS_DIR)/base.make include $(TESTS_DIR)/base.make
include $(TESTS_DIR)/objc.make
A_CPP = A.cpp A_MM = A.mm
CLANG_OPTIONS = -c $(OBJCPP_CLANG_OPTIONS) -fobjc-arc
TEST_DETERMINATOR_RESULT = infer-out-mod2/diff_determinator.json TEST_DETERMINATOR_RESULT = infer-out-mod2/diff_determinator.json
DIFF_OUTPUT = diff.mod2.test DIFF_OUTPUT = diff.mod2.test
INFER_OPTIONS = --test-determinator --process-clang-ast --no-linters --no-capture INFER_OPTIONS = --test-determinator --process-clang-ast --no-linters --no-capture
@ -16,21 +18,21 @@ INFER_OPTIONS = --test-determinator --process-clang-ast --no-linters --no-captur
default: $(TEST_DETERMINATOR_RESULT) default: $(TEST_DETERMINATOR_RESULT)
$(DIFF_OUTPUT): $(DIFF_OUTPUT):
$(QUIET)echo -n '$(A_CPP):' > diff.mod1.test $(QUIET)echo -n '$(A_MM):' > diff.mod1.test
$(QUIET)(diff -N --unchanged-line-format="U" --old-line-format="O" --new-line-format="N" \ $(QUIET)(diff -N --unchanged-line-format="U" --old-line-format="O" --new-line-format="N" \
orig-$(A_CPP) mod1-$(A_CPP) || [ $$? = 1 ]) >> diff.mod1.test orig-$(A_MM) mod1-$(A_MM) || [ $$? = 1 ]) >> diff.mod1.test
$(QUIET)echo -n '$(A_CPP):' > diff.mod2.test $(QUIET)echo -n '$(A_MM):' > diff.mod2.test
$(QUIET)(diff -N --unchanged-line-format="U" --old-line-format="O" --new-line-format="N" \ $(QUIET)(diff -N --unchanged-line-format="U" --old-line-format="O" --new-line-format="N" \
orig-$(A_CPP) mod2-$(A_CPP) || [ $$? = 1 ]) >> diff.mod2.test orig-$(A_MM) mod2-$(A_MM) || [ $$? = 1 ]) >> diff.mod2.test
$(TEST_DETERMINATOR_RESULT): $(DIFF_OUTPUT) $(TEST_DETERMINATOR_RESULT): $(DIFF_OUTPUT)
$(QUIET)$(call silent_on_success,Testing clang test-determinator with set of changes in mod1,\ $(QUIET)$(call silent_on_success,Testing clang test-determinator with set of changes in mod1,\
cp mod1-$(A_CPP) $(A_CPP);\ cp mod1-$(A_MM) $(A_MM);\
$(INFER_BIN) -o infer-out-mod1 $(INFER_OPTIONS) --profiler-samples profiler_samples.json --modified-lines diff.mod1.test -- clang -c $(A_CPP)) $(INFER_BIN) -o infer-out-mod1 $(INFER_OPTIONS) --profiler-samples profiler_samples.json --modified-lines diff.mod1.test -- clang $(CLANG_OPTIONS) $(A_MM))
$(QUIET)$(call silent_on_success,Testing test-determinator-clang with set of changes in mod2,\ $(QUIET)$(call silent_on_success,Testing test-determinator-clang with set of changes in mod2,\
cp mod2-$(A_CPP) $(A_CPP);\ cp mod2-$(A_MM) $(A_MM);\
$(INFER_BIN) -o infer-out-mod2 $(INFER_OPTIONS) --profiler-samples profiler_samples.json --modified-lines diff.mod2.test -- clang -c $(A_CPP)) $(INFER_BIN) -o infer-out-mod2 $(INFER_OPTIONS) --profiler-samples profiler_samples.json --modified-lines diff.mod2.test -- clang $(CLANG_OPTIONS) $(A_MM))
$(QUIET) rm $(A_CPP) $(QUIET) rm $(A_MM)
.PHONY: test .PHONY: test
test: $(TEST_DETERMINATOR_RESULT) test: $(TEST_DETERMINATOR_RESULT)

@ -1,30 +0,0 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <algorithm>
int example_function1() { return 111; }
int example_function2() { return 2; }
namespace Shapes {
class Cube {
int size;
public:
void set_size(int);
int area() { return size * size * size; };
void sort(Cube*, unsigned);
};
void Cube::set_size(int s) { size = s; }
void Cube::sort(Cube* xs, unsigned n) {
std::sort(xs, xs + n, [](Cube a, Cube b) { return (a.area() > b.area()); });
}
} // namespace Shapes

@ -0,0 +1,58 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <algorithm>
#import <Foundation/Foundation.h>
int example_function1() { return 111; } // change here
int example_function2() { return 2; }
namespace Shapes {
class Cube {
int size;
public:
void set_size(int);
int area() { return size * size * size; }; // change here
void sort(Cube*, unsigned);
};
void Cube::set_size(int s) { size = s; }
void Cube::sort(Cube* xs, unsigned n) {
std::sort(xs, xs + n, [](Cube a, Cube b) { return (a.area() < b.area()); });
}
} // namespace Shapes
@interface Person : NSObject
@property NSString* name;
- (BOOL)isEqual:(id)obj;
- (void)printName;
@end
@implementation Person
- (BOOL)isEqual:(id)other { // change here
BOOL result = NO;
if ([other isKindOfClass:[self class]]) {
Person* otherObject = other;
result = [self.name isEqualToString:[otherObject name]];
}
return result;
}
- (void)printName {
NSLog(@"The person's name is %@", _name);
}
@end

@ -6,10 +6,11 @@
*/ */
#include <algorithm> #include <algorithm>
#import <Foundation/Foundation.h>
int example_function1() { return 1; } int example_function1() { return 1; }
int example_function2() { return 222; } int example_function2() { return 222; } // change here
namespace Shapes { namespace Shapes {
@ -25,7 +26,34 @@ class Cube {
void Cube::set_size(int s) { size = s; } void Cube::set_size(int s) { size = s; }
void Cube::sort(Cube* xs, unsigned n) { void Cube::sort(Cube* xs, unsigned n) {
// this is a lambda folks // this is a lambda folks //change here
std::sort(xs, xs + n, [](Cube a, Cube b) { return (a.area() < b.area()); }); std::sort(xs, xs + n, [](Cube a, Cube b) { return (a.area() < b.area()); });
} }
} // namespace Shapes } // namespace Shapes
@interface Person : NSObject
@property NSString* name;
- (BOOL)isEqual:(id)obj;
- (void)printName;
@end
@implementation Person
- (BOOL)isEqual:(id)obj {
BOOL result = NO;
if ([obj isKindOfClass:[self class]]) {
Person* otherObject = obj;
result = [self.name isEqualToString:[otherObject name]];
}
return result;
}
- (void)printName {
NSLog(@"The name is %@", _name); // change here
}
@end

@ -6,6 +6,7 @@
*/ */
#include <algorithm> #include <algorithm>
#import <Foundation/Foundation.h>
int example_function1() { return 1; } int example_function1() { return 1; }
@ -28,3 +29,30 @@ void Cube::sort(Cube* xs, unsigned n) {
std::sort(xs, xs + n, [](Cube a, Cube b) { return (a.area() < b.area()); }); std::sort(xs, xs + n, [](Cube a, Cube b) { return (a.area() < b.area()); });
} }
} // namespace Shapes } // namespace Shapes
@interface Person : NSObject
@property NSString* name;
- (BOOL)isEqual:(id)obj;
- (void)printName;
@end
@implementation Person
- (BOOL)isEqual:(id)obj {
BOOL result = NO;
if ([obj isKindOfClass:[self class]]) {
Person* otherObject = obj;
result = [self.name isEqualToString:[otherObject name]];
}
return result;
}
- (void)printName {
NSLog(@"The person's name is %@", _name);
}
@end

@ -1,7 +1,7 @@
[ [
{ {
"field1": {}, "field1": {},
"test": "label1", "test": "label1_c_function",
"field2": {}, "field2": {},
"native_symbols": [ "native_symbols": [
{ {
@ -18,7 +18,7 @@
"field1": {}, "field1": {},
"field2": {}, "field2": {},
"field3": {}, "field3": {},
"test": "label2", "test": "label2_c_function",
"field4": {}, "field4": {},
"native_symbols": [ "native_symbols": [
{ {
@ -31,5 +31,39 @@
], ],
"field5": {}, "field5": {},
"field6": {} "field6": {}
},
{
"field1": {},
"field2": {},
"field3": {},
"test": "label1_objc_method",
"field4": {},
"native_symbols": [
{
"name": "-[Person isEqual:]"
},
{
"name": "exampleMethod2"
}
],
"field5": {},
"field6": {}
},
{
"field1": {},
"field2": {},
"field3": {},
"test": "label2_objc_method",
"field4": {},
"native_symbols": [
{
"name": "-[Person printName]"
},
{
"name": "exampleMethod3"
}
],
"field5": {},
"field6": {}
} }
] ]

@ -1 +1 @@
["label1"] ["label1_objc_method","label1_c_function"]

@ -1 +1 @@
["label2"] ["label2_objc_method","label2_c_function"]
Loading…
Cancel
Save