[cost] Add tests run with ARC/non-ARC sources

Summary: This diff adds some tests run with ARC/non-ARC compiled objective-c sources.

Reviewed By: ezgicicek

Differential Revision: D23542135

fbshipit-source-id: 8e089666b
master
Sungkeun Cho 4 years ago committed by Facebook GitHub Bot
parent b62c3f55b9
commit 6ff1a42b6a

@ -0,0 +1,21 @@
# 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.
ROOT_DIR = $(TESTS_DIR)/../..
CLEAN_EXTRA += duplicates.txt
OBJECTS = $(foreach source,$(filter %.c %.cpp %.m %.mm,$(SOURCES)),$(basename $(source)).o)
include $(TESTS_DIR)/infer.make
include $(TESTS_DIR)/clang-base.make
infer-out$(TEST_SUFFIX)/report.json: $(CLANG_DEPS) $(SOURCES) $(HEADERS) $(TESTS_DIR)/.inferconfig $(MAKEFILE_LIST)
$(QUIET)$(call silent_on_success,Testing infer/clang in $(TEST_REL_DIR),\
$(INFER_BIN) capture --results-dir $(@D) --dump-duplicate-symbols $(INFER_OPTIONS) \
-- clang -fno-objc-arc $(CLANG_OPTIONS) $(SOURCES_NO_ARC) && \
$(INFER_BIN) capture --continue --results-dir $(@D) --dump-duplicate-symbols $(INFER_OPTIONS) \
-- clang -fobjc-arc $(CLANG_OPTIONS) $(SOURCES_ARC) && \
$(INFER_BIN) analyze --results-dir $(@D) --dump-duplicate-symbols $(INFER_OPTIONS))

@ -11,8 +11,10 @@ INFERPRINT_OPTIONS = --issues-tests
INFERPRINT_COST_OPTIONS = --cost-tests-only-autoreleasepool --cost-issues-tests
SOURCES = $(wildcard *.m)
SOURCES_ARC = $(wildcard arc_*.m)
SOURCES_NO_ARC = $(filter-out $(SOURCES_ARC),$(SOURCES))
include $(TESTS_DIR)/clang.make
include $(TESTS_DIR)/clang-arc-no-arc.make
include $(TESTS_DIR)/objc.make
include $(TESTS_DIR)/cost.make

@ -0,0 +1,53 @@
/*
* 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.
*/
#import <Foundation/Foundation.h>
#import "no_arc_callee.h"
@interface ArcCaller : NSObject
@end
@implementation ArcCaller
- (void)callAllocObject_zero:(int)n {
for (int i = 0; i < n; i++) {
NoArcCallee* obj = [NoArcCallee allocObject];
}
}
- (void)callNewObject_zero:(int)n {
for (int i = 0; i < n; i++) {
NoArcCallee* obj = [NoArcCallee newObject];
}
}
- (void)callCopyObject_zero:(int)n x:(NoArcCallee*)x {
for (int i = 0; i < n; i++) {
NoArcCallee* obj = [NoArcCallee copyObject:x];
}
}
- (void)callMutableCopyObject_zero:(int)n x:(NoArcCallee*)x {
for (int i = 0; i < n; i++) {
NoArcCallee* obj = [NoArcCallee mutableCopyObject:x];
}
}
- (void)callGiveMeObject_linear:(int)n {
for (int i = 0; i < n; i++) {
NoArcCallee* obj = [NoArcCallee giveMeObject];
}
}
- (void)callGiveMeObject_autoreleasepool_zero:(int)n {
for (int i = 0; i < n; i++) {
@autoreleasepool {
NoArcCallee* obj = [NoArcCallee giveMeObject];
}
}
}
@end

@ -1,3 +1,10 @@
codetoanalyze/objc/autoreleasepool/arc_caller.m, ArcCaller.callAllocObject_zero:, 0, OnUIThread:false, []
codetoanalyze/objc/autoreleasepool/arc_caller.m, ArcCaller.callCopyObject_zero:x:, 0, OnUIThread:false, []
codetoanalyze/objc/autoreleasepool/arc_caller.m, ArcCaller.callGiveMeObject_autoreleasepool_zero:, 0, OnUIThread:false, []
codetoanalyze/objc/autoreleasepool/arc_caller.m, ArcCaller.callGiveMeObject_linear:, n, OnUIThread:false, [{n},Loop]
codetoanalyze/objc/autoreleasepool/arc_caller.m, ArcCaller.callMutableCopyObject_zero:x:, 0, OnUIThread:false, []
codetoanalyze/objc/autoreleasepool/arc_caller.m, ArcCaller.callNewObject_zero:, 0, OnUIThread:false, []
codetoanalyze/objc/autoreleasepool/arc_caller.m, ArcCaller.dealloc, 0, OnUIThread:false, []
codetoanalyze/objc/autoreleasepool/basic.m, Basic.autoreleased_in_autoreleasepool_zero:, 0, OnUIThread:false, []
codetoanalyze/objc/autoreleasepool/basic.m, Basic.autoreleased_in_loop_linear:, n, OnUIThread:false, [{n},Loop]
codetoanalyze/objc/autoreleasepool/basic.m, Basic.autoreleased_in_loop_nested_zero:, 0, OnUIThread:false, []
@ -8,3 +15,9 @@ codetoanalyze/objc/autoreleasepool/basic.m, Basic.call_no_autorelease_zero, 0,
codetoanalyze/objc/autoreleasepool/basic.m, Basic.dealloc, 0, OnUIThread:false, []
codetoanalyze/objc/autoreleasepool/basic.m, Basic.loop_in_autoreleasepool_zero:, 0, OnUIThread:false, []
codetoanalyze/objc/autoreleasepool/basic.m, Basic.no_autoreleased_in_loop_zero:, 0, OnUIThread:false, []
codetoanalyze/objc/autoreleasepool/no_arc_callee.m, NoArcCallee.allocObject, 0, OnUIThread:false, []
codetoanalyze/objc/autoreleasepool/no_arc_callee.m, NoArcCallee.copyObject:, 0, OnUIThread:false, []
codetoanalyze/objc/autoreleasepool/no_arc_callee.m, NoArcCallee.dealloc, 0, OnUIThread:false, []
codetoanalyze/objc/autoreleasepool/no_arc_callee.m, NoArcCallee.giveMeObject, 1, OnUIThread:false, []
codetoanalyze/objc/autoreleasepool/no_arc_callee.m, NoArcCallee.mutableCopyObject:, 0, OnUIThread:false, []
codetoanalyze/objc/autoreleasepool/no_arc_callee.m, NoArcCallee.newObject, 0, OnUIThread:false, []

@ -0,0 +1,21 @@
/*
* 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.
*/
#import <Foundation/Foundation.h>
@interface NoArcCallee : NSObject
+ (NoArcCallee*)allocObject;
+ (NoArcCallee*)newObject;
+ (NoArcCallee*)copyObject:(NoArcCallee*)obj;
+ (NoArcCallee*)mutableCopyObject:(NoArcCallee*)obj;
+ (NoArcCallee*)giveMeObject;
@end

@ -0,0 +1,35 @@
/*
* 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.
*/
#import <Foundation/Foundation.h>
#import "no_arc_callee.h"
@implementation NoArcCallee
+ (NoArcCallee*)allocObject {
return [NoArcCallee alloc];
}
/* Since the checker cares about calling `autorelease` only, we define the
following functions as returning a new object simply. */
+ (NoArcCallee*)newObject {
return [[NoArcCallee alloc] init];
}
+ (NoArcCallee*)copyObject:(NoArcCallee*)obj {
return [[NoArcCallee alloc] init];
}
+ (NoArcCallee*)mutableCopyObject:(NoArcCallee*)obj {
return [[NoArcCallee alloc] init];
}
+ (NoArcCallee*)giveMeObject {
return [[[NoArcCallee alloc] init] autorelease];
}
@end
Loading…
Cancel
Save