diff --git a/infer/src/test_determinator/testDeterminator.ml b/infer/src/test_determinator/testDeterminator.ml index b47e3eb15..b5e19b095 100644 --- a/infer/src/test_determinator/testDeterminator.ml +++ b/infer/src/test_determinator/testDeterminator.ml @@ -206,6 +206,8 @@ let match_profiler_samples_affected_methods native_symbols affected_methods = match affected_method with | Some (ClangProc.CFunction {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 (* TODO: deal with mangled names, other method kinds *) diff --git a/infer/tests/build_systems/clang_test_determinator/Makefile b/infer/tests/build_systems/clang_test_determinator/Makefile index 6bb366d98..f5eb8c780 100644 --- a/infer/tests/build_systems/clang_test_determinator/Makefile +++ b/infer/tests/build_systems/clang_test_determinator/Makefile @@ -7,8 +7,10 @@ TESTS_DIR = ../.. 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 DIFF_OUTPUT = diff.mod2.test 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) $(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" \ - orig-$(A_CPP) mod1-$(A_CPP) || [ $$? = 1 ]) >> diff.mod1.test - $(QUIET)echo -n '$(A_CPP):' > diff.mod2.test + orig-$(A_MM) mod1-$(A_MM) || [ $$? = 1 ]) >> diff.mod1.test + $(QUIET)echo -n '$(A_MM):' > diff.mod2.test $(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) $(QUIET)$(call silent_on_success,Testing clang test-determinator with set of changes in mod1,\ - cp mod1-$(A_CPP) $(A_CPP);\ - $(INFER_BIN) -o infer-out-mod1 $(INFER_OPTIONS) --profiler-samples profiler_samples.json --modified-lines diff.mod1.test -- clang -c $(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 $(CLANG_OPTIONS) $(A_MM)) $(QUIET)$(call silent_on_success,Testing test-determinator-clang with set of changes in mod2,\ - cp mod2-$(A_CPP) $(A_CPP);\ - $(INFER_BIN) -o infer-out-mod2 $(INFER_OPTIONS) --profiler-samples profiler_samples.json --modified-lines diff.mod2.test -- clang -c $(A_CPP)) - $(QUIET) rm $(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 $(CLANG_OPTIONS) $(A_MM)) + $(QUIET) rm $(A_MM) .PHONY: test test: $(TEST_DETERMINATOR_RESULT) diff --git a/infer/tests/build_systems/clang_test_determinator/mod1-A.cpp b/infer/tests/build_systems/clang_test_determinator/mod1-A.cpp deleted file mode 100644 index 4177d5de0..000000000 --- a/infer/tests/build_systems/clang_test_determinator/mod1-A.cpp +++ /dev/null @@ -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 - -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 diff --git a/infer/tests/build_systems/clang_test_determinator/mod1-A.mm b/infer/tests/build_systems/clang_test_determinator/mod1-A.mm new file mode 100644 index 000000000..3e026d875 --- /dev/null +++ b/infer/tests/build_systems/clang_test_determinator/mod1-A.mm @@ -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 +#import + +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 diff --git a/infer/tests/build_systems/clang_test_determinator/mod2-A.cpp b/infer/tests/build_systems/clang_test_determinator/mod2-A.mm similarity index 51% rename from infer/tests/build_systems/clang_test_determinator/mod2-A.cpp rename to infer/tests/build_systems/clang_test_determinator/mod2-A.mm index 0ded1e827..1782cccee 100644 --- a/infer/tests/build_systems/clang_test_determinator/mod2-A.cpp +++ b/infer/tests/build_systems/clang_test_determinator/mod2-A.mm @@ -6,10 +6,11 @@ */ #include +#import int example_function1() { return 1; } -int example_function2() { return 222; } +int example_function2() { return 222; } // change here namespace Shapes { @@ -25,7 +26,34 @@ class Cube { void Cube::set_size(int s) { size = s; } 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()); }); } } // 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 diff --git a/infer/tests/build_systems/clang_test_determinator/orig-A.cpp b/infer/tests/build_systems/clang_test_determinator/orig-A.mm similarity index 58% rename from infer/tests/build_systems/clang_test_determinator/orig-A.cpp rename to infer/tests/build_systems/clang_test_determinator/orig-A.mm index d7f9a599a..5cfd7899d 100644 --- a/infer/tests/build_systems/clang_test_determinator/orig-A.cpp +++ b/infer/tests/build_systems/clang_test_determinator/orig-A.mm @@ -6,6 +6,7 @@ */ #include +#import 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()); }); } } // 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 diff --git a/infer/tests/build_systems/clang_test_determinator/profiler_samples.json b/infer/tests/build_systems/clang_test_determinator/profiler_samples.json index 6e5eb8373..2137e4126 100644 --- a/infer/tests/build_systems/clang_test_determinator/profiler_samples.json +++ b/infer/tests/build_systems/clang_test_determinator/profiler_samples.json @@ -1,7 +1,7 @@ [ { "field1": {}, - "test": "label1", + "test": "label1_c_function", "field2": {}, "native_symbols": [ { @@ -18,7 +18,7 @@ "field1": {}, "field2": {}, "field3": {}, - "test": "label2", + "test": "label2_c_function", "field4": {}, "native_symbols": [ { @@ -31,5 +31,39 @@ ], "field5": {}, "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": {} } ] diff --git a/infer/tests/build_systems/clang_test_determinator/test_determinator.json.mod1.exp b/infer/tests/build_systems/clang_test_determinator/test_determinator.json.mod1.exp index 262097c58..2987c0c74 100644 --- a/infer/tests/build_systems/clang_test_determinator/test_determinator.json.mod1.exp +++ b/infer/tests/build_systems/clang_test_determinator/test_determinator.json.mod1.exp @@ -1 +1 @@ -["label1"] \ No newline at end of file +["label1_objc_method","label1_c_function"] \ No newline at end of file diff --git a/infer/tests/build_systems/clang_test_determinator/test_determinator.json.mod2.exp b/infer/tests/build_systems/clang_test_determinator/test_determinator.json.mod2.exp index 1b7164c2e..7869ab3b6 100644 --- a/infer/tests/build_systems/clang_test_determinator/test_determinator.json.mod2.exp +++ b/infer/tests/build_systems/clang_test_determinator/test_determinator.json.mod2.exp @@ -1 +1 @@ -["label2"] \ No newline at end of file +["label2_objc_method","label2_c_function"] \ No newline at end of file