History

1. support .c in makefile generator. 2. add test to check C interfaces.

jwwang committed 12 years ago

Commit 4fa810d1 parent b51963c5 files · +183 −3Browse files

Unified · Split

5 files
  1. Makefile +1 −0
  2. build/mktargets.py +24 −3
  3. test/c_interface_test.c +32 −0
  4. test/cpp_interface_test.cpp +116 −0
  5. test/targets.mk +10 −0
Makefile+1−0
@@ -64,6 +64,7 @@ ASMFLAGS += $(ASMFLAGS_PLATFORM) -DNO_DYNAMIC_VP · 63 unmodified lines
64#### No user-serviceable parts below this line64#### No user-serviceable parts below this line
65ifneq ($(V),Yes)65ifneq ($(V),Yes)
66 QUIET_CXX = @printf "CXX\t$@\n";66 QUIET_CXX = @printf "CXX\t$@\n";
67 QUIET_CC = @printf "CC\t$@\n";
67 QUIET_ASM = @printf "ASM\t$@\n";68 QUIET_ASM = @printf "ASM\t$@\n";
68 QUIET_AR = @printf "AR\t$@\n";69 QUIET_AR = @printf "AR\t$@\n";
69 QUIET = @70 QUIET = @
build/mktargets.py+24−3
@@ -30,6 +30,14 @@ def write_cpp_rule_pattern(f): · 29 unmodified lines
30 f.write('\t$(QUIET_CXX)$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(' + PREFIX + '_CFLAGS) $(' + PREFIX + '_INCLUDES) -c $(CXX_O) $<\n')30 f.write('\t$(QUIET_CXX)$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(' + PREFIX + '_CFLAGS) $(' + PREFIX + '_INCLUDES) -c $(CXX_O) $<\n')
31 f.write("\n")31 f.write("\n")
32 32
33def write_c_rule_pattern(f):
34 src = "$(%s_SRCDIR)/%%.c"%(PREFIX)
35 dst = "$(%s_SRCDIR)/%%.o"%(PREFIX)
36
37 f.write("%s: %s\n"%(dst, src))
38 f.write('\t$(QUIET_CC)$(CC) $(CFLAGS) $(INCLUDES) $(' + PREFIX + '_CFLAGS) $(' + PREFIX + '_INCLUDES) -c $(CXX_O) $<\n')
39 f.write("\n")
40
33def write_asm_rule_pattern(f):41def write_asm_rule_pattern(f):
34 src = "$(%s_SRCDIR)/%%.asm"%(PREFIX)42 src = "$(%s_SRCDIR)/%%.asm"%(PREFIX)
35 dst = "$(%s_SRCDIR)/%%.o"%(PREFIX)43 dst = "$(%s_SRCDIR)/%%.o"%(PREFIX)
@@ -42,6 +50,7 @@ def write_asm_rule_pattern(f): · 6 unmodified lines
42def find_sources():50def find_sources():
43 cpp_files = []51 cpp_files = []
44 asm_files = []52 asm_files = []
53 c_files = []
45 print EXCLUDE54 print EXCLUDE
46 for dir in os.walk("."):55 for dir in os.walk("."):
47 for file in dir[2]:56 for file in dir[2]:
@@ -50,7 +59,9 @@ def find_sources(): · 2 unmodified lines
50 cpp_files.append(os.path.join(dir[0].strip('./'), file))59 cpp_files.append(os.path.join(dir[0].strip('./'), file))
51 if os.path.splitext(file)[1] == '.asm':60 if os.path.splitext(file)[1] == '.asm':
52 asm_files.append(os.path.join(dir[0].strip('./'), file))61 asm_files.append(os.path.join(dir[0].strip('./'), file))
53 return [cpp_files, asm_files]62 if os.path.splitext(file)[1] == '.c':
63 c_files.append(os.path.join(dir[0].strip('./'), file))
64 return [cpp_files, asm_files, c_files]
54 65
55 66
56args = parser.parse_args()67args = parser.parse_args()
@@ -80,7 +91,7 @@ try: · 23 unmodified lines
80except:91except:
81 sys.exit(1)92 sys.exit(1)
82 93
83(cpp, asm) = find_sources()94(cpp, asm, cfiles) = find_sources()
84 95
85 96
86 97
@@ -91,7 +102,14 @@ f.write("%s_CPP_SRCS=\\\n"%(PREFIX)) · 4 unmodified lines
91for c in cpp:102for c in cpp:
92 f.write("\t$(%s_SRCDIR)/%s\\\n"%(PREFIX, c))103 f.write("\t$(%s_SRCDIR)/%s\\\n"%(PREFIX, c))
93f.write("\n")104f.write("\n")
94f.write("%s_OBJS += $(%s_CPP_SRCS:%s=.o)\n"%(PREFIX, PREFIX, CPP_SUFFIX))105f.write("%s_OBJS += $(%s_CPP_SRCS:%s=.o)\n\n"%(PREFIX, PREFIX, CPP_SUFFIX))
106
107if len(cfiles) > 0:
108 f.write("%s_C_SRCS=\\\n"%(PREFIX))
109 for cfile in cfiles:
110 f.write("\t$(%s_SRCDIR)/%s\\\n"%(PREFIX, cfile))
111 f.write("\n")
112 f.write("%s_OBJS += $(%s_C_SRCS:.c=.o)\n\n"%(PREFIX, PREFIX))
95 113
96if len(asm) > 0:114if len(asm) > 0:
97 f.write("ifeq ($(USE_ASM), Yes)\n")115 f.write("ifeq ($(USE_ASM), Yes)\n")
@@ -106,6 +124,9 @@ f.write("OBJS += $(%s_OBJS)\n"%PREFIX) · 8 unmodified lines
106 124
107write_cpp_rule_pattern(f)125write_cpp_rule_pattern(f)
108 126
127if len(cfiles) > 0:
128 write_c_rule_pattern(f)
129
109if len(asm) > 0:130if len(asm) > 0:
110 write_asm_rule_pattern(f)131 write_asm_rule_pattern(f)
111 132
test/c_interface_test.c+32−0
@@ -0,0 +1,32 @@
1#include "codec_api.h"
2
3// Cast to this function type to ignore other parameters.
4typedef int (*Func)(void*);
5#define CALL(p, m) (((Func)((*p)->m))(p))
6// Check if the function return an expected number.
7#define CHECK(n, p, m) check(n, CALL(p, m), #m)
8
9typedef void(*CheckFunc)(int, int, const char*);
10
11void CheckEncoderInterface(ISVCEncoder* p, CheckFunc check) {
12 CHECK(1, p, Initialize);
13 CHECK(2, p, Initialize2);
14 CHECK(3, p, Uninitialize);
15 CHECK(4, p, EncodeFrame);
16 CHECK(5, p, EncodeFrame2);
17 CHECK(6, p, EncodeParameterSets);
18 CHECK(7, p, PauseFrame);
19 CHECK(8, p, ForceIntraFrame);
20 CHECK(9, p, SetOption);
21 CHECK(10, p, GetOption);
22}
23
24void CheckDecoderInterface(ISVCDecoder* p, CheckFunc check) {
25 CHECK(1, p, Initialize);
26 CHECK(2, p, Uninitialize);
27 CHECK(3, p, DecodeFrame);
28 CHECK(4, p, DecodeFrame2);
29 CHECK(5, p, DecodeFrameEx);
30 CHECK(6, p, SetOption);
31 CHECK(7, p, GetOption);
32}
test/cpp_interface_test.cpp+116−0
@@ -0,0 +1,116 @@
1#include <gtest/gtest.h>
2#include "codec_api.h"
3
4static void CheckFunctionOrder(int expect, int actual, const char* name) {
5 EXPECT_EQ(expect, actual) << "Wrong function order: " << name;
6}
7
8typedef void(*CheckFunc)(int, int, const char*);
9extern "C" void CheckEncoderInterface(ISVCEncoder* p, CheckFunc);
10extern "C" void CheckDecoderInterface(ISVCDecoder* p, CheckFunc);
11
12// Store the 'this' pointer to verify 'this' is received as expected from C code.
13static void* gThis;
14
15/**
16 * Return a unique number for each virtual function so that we are able to
17 * check if the order of functions in the virtual table is as expected.
18 */
19struct SVCEncoderImpl : public ISVCEncoder {
20 virtual ~SVCEncoderImpl() {}
21 virtual int EXTAPI Initialize(SVCEncodingParam* pParam,
22 const INIT_TYPE kiInitType) {
23 EXPECT_TRUE(gThis == this);
24 return 1;
25 }
26 virtual int EXTAPI Initialize2(void* pParam, const INIT_TYPE kiInitType) {
27 EXPECT_TRUE(gThis == this);
28 return 2;
29 }
30 virtual int EXTAPI Uninitialize() {
31 EXPECT_TRUE(gThis == this);
32 return 3;
33 }
34 virtual int EXTAPI EncodeFrame(const unsigned char* kpSrc,
35 SFrameBSInfo* pBsInfo) {
36 EXPECT_TRUE(gThis == this);
37 return 4;
38 }
39 virtual int EXTAPI EncodeFrame2(const SSourcePicture** kppSrcPicList,
40 int nSrcPicNum, SFrameBSInfo* pBsInfo) {
41 EXPECT_TRUE(gThis == this);
42 return 5;
43 }
44 virtual int EXTAPI EncodeParameterSets(SFrameBSInfo* pBsInfo) {
45 EXPECT_TRUE(gThis == this);
46 return 6;
47 }
48 virtual int EXTAPI PauseFrame(const unsigned char* kpSrc,
49 SFrameBSInfo* pBsInfo) {
50 EXPECT_TRUE(gThis == this);
51 return 7;
52 }
53 virtual int EXTAPI ForceIntraFrame(bool bIDR) {
54 EXPECT_TRUE(gThis == this);
55 return 8;
56 }
57 virtual int EXTAPI SetOption(ENCODER_OPTION eOptionId, void* pOption) {
58 EXPECT_TRUE(gThis == this);
59 return 9;
60 }
61 virtual int EXTAPI GetOption(ENCODER_OPTION eOptionId, void* pOption) {
62 EXPECT_TRUE(gThis == this);
63 return 10;
64 }
65};
66
67struct SVCDecoderImpl : public ISVCDecoder {
68 virtual ~SVCDecoderImpl() {}
69 virtual long EXTAPI Initialize(void* pParam, const INIT_TYPE iInitType) {
70 EXPECT_TRUE(gThis == this);
71 return 1;
72 }
73 virtual long EXTAPI Uninitialize() {
74 EXPECT_TRUE(gThis == this);
75 return 2;
76 }
77 virtual DECODING_STATE EXTAPI DecodeFrame(const unsigned char* pSrc,
78 const int iSrcLen, unsigned char** ppDst, int* pStride,
79 int& iWidth, int& iHeight) {
80 EXPECT_TRUE(gThis == this);
81 return static_cast<DECODING_STATE>(3);
82 }
83 virtual DECODING_STATE EXTAPI DecodeFrame2(const unsigned char* pSrc,
84 const int iSrcLen, void** ppDst, SBufferInfo* pDstInfo) {
85 EXPECT_TRUE(gThis == this);
86 return static_cast<DECODING_STATE>(4);
87 }
88 virtual DECODING_STATE EXTAPI DecodeFrameEx(const unsigned char* pSrc,
89 const int iSrcLen, unsigned char* pDst, int iDstStride,
90 int& iDstLen, int& iWidth, int& iHeight, int& iColorFormat) {
91 EXPECT_TRUE(gThis == this);
92 return static_cast<DECODING_STATE>(5);
93 }
94 virtual long EXTAPI SetOption (DECODER_OPTION eOptionId, void* pOption) {
95 EXPECT_TRUE(gThis == this);
96 return 6;
97 }
98 virtual long EXTAPI GetOption (DECODER_OPTION eOptionId, void* pOption) {
99 EXPECT_TRUE(gThis == this);
100 return 7;
101 }
102};
103
104TEST(ISVCEncoderTest, CheckFunctionOrder) {
105 SVCEncoderImpl* p = new SVCEncoderImpl;
106 gThis = p;
107 CheckEncoderInterface(p, CheckFunctionOrder);
108 delete p;
109}
110
111TEST(ISVCDecoderTest, CheckFunctionOrder) {
112 SVCDecoderImpl* p = new SVCDecoderImpl;
113 gThis = p;
114 CheckDecoderInterface(p, CheckFunctionOrder);
115 delete p;
116}
test/targets.mk+10−0
@@ -6,12 +6,22 @@ CODEC_UNITTEST_CPP_SRCS=\ · 5 unmodified lines
6 $(CODEC_UNITTEST_SRCDIR)/decoder_test.cpp\6 $(CODEC_UNITTEST_SRCDIR)/decoder_test.cpp\
7 $(CODEC_UNITTEST_SRCDIR)/encoder_test.cpp\7 $(CODEC_UNITTEST_SRCDIR)/encoder_test.cpp\
8 $(CODEC_UNITTEST_SRCDIR)/simple_test.cpp\8 $(CODEC_UNITTEST_SRCDIR)/simple_test.cpp\
9 $(CODEC_UNITTEST_SRCDIR)/./cpp_interface_test.cpp\
9 10
10CODEC_UNITTEST_OBJS += $(CODEC_UNITTEST_CPP_SRCS:.cpp=.o)11CODEC_UNITTEST_OBJS += $(CODEC_UNITTEST_CPP_SRCS:.cpp=.o)
12
13CODEC_UNITTEST_C_SRCS=\
14 $(CODEC_UNITTEST_SRCDIR)/./c_interface_test.c\
15
16CODEC_UNITTEST_OBJS += $(CODEC_UNITTEST_C_SRCS:.c=.o)
17
11OBJS += $(CODEC_UNITTEST_OBJS)18OBJS += $(CODEC_UNITTEST_OBJS)
12$(CODEC_UNITTEST_SRCDIR)/%.o: $(CODEC_UNITTEST_SRCDIR)/%.cpp19$(CODEC_UNITTEST_SRCDIR)/%.o: $(CODEC_UNITTEST_SRCDIR)/%.cpp
13 $(QUIET_CXX)$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(CODEC_UNITTEST_CFLAGS) $(CODEC_UNITTEST_INCLUDES) -c $(CXX_O) $<20 $(QUIET_CXX)$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(CODEC_UNITTEST_CFLAGS) $(CODEC_UNITTEST_INCLUDES) -c $(CXX_O) $<
14 21
22$(CODEC_UNITTEST_SRCDIR)/%.o: $(CODEC_UNITTEST_SRCDIR)/%.c
23 $(QUIET_CXX)$(CC) $(CFLAGS) $(INCLUDES) $(CODEC_UNITTEST_CFLAGS) $(CODEC_UNITTEST_INCLUDES) -c $(CXX_O) $<
24
15codec_unittest$(EXEEXT): $(CODEC_UNITTEST_OBJS) $(LIBS) $(CODEC_UNITTEST_LIBS) $(CODEC_UNITTEST_DEPS)25codec_unittest$(EXEEXT): $(CODEC_UNITTEST_OBJS) $(LIBS) $(CODEC_UNITTEST_LIBS) $(CODEC_UNITTEST_DEPS)
16 $(QUIET_CXX)$(CXX) $(CXX_LINK_O) $(CODEC_UNITTEST_OBJS) $(CODEC_UNITTEST_LDFLAGS) $(CODEC_UNITTEST_LIBS) $(LDFLAGS) $(LIBS)26 $(QUIET_CXX)$(CXX) $(CXX_LINK_O) $(CODEC_UNITTEST_OBJS) $(CODEC_UNITTEST_LDFLAGS) $(CODEC_UNITTEST_LIBS) $(LDFLAGS) $(LIBS)
17 27

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t