锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久成人精品,久久精品中文字幕久久,久久久久久久久久久精品尤物http://www.shnenglu.com/tankzhouqiang/zh-cnWed, 07 May 2025 01:48:30 GMTWed, 07 May 2025 01:48:30 GMT60skiplisthttp://www.shnenglu.com/tankzhouqiang/archive/2014/05/11/206903.html鍛ㄥ己鍛ㄥ己Sun, 11 May 2014 15:03:00 GMThttp://www.shnenglu.com/tankzhouqiang/archive/2014/05/11/206903.htmlhttp://www.shnenglu.com/tankzhouqiang/comments/206903.htmlhttp://www.shnenglu.com/tankzhouqiang/archive/2014/05/11/206903.html#Feedback0http://www.shnenglu.com/tankzhouqiang/comments/commentRss/206903.htmlhttp://www.shnenglu.com/tankzhouqiang/services/trackbacks/206903.html

鍛ㄥ己 2014-05-11 23:03 鍙戣〃璇勮
]]>
2013http://www.shnenglu.com/tankzhouqiang/archive/2014/01/03/205150.html鍛ㄥ己鍛ㄥ己Fri, 03 Jan 2014 13:17:00 GMThttp://www.shnenglu.com/tankzhouqiang/archive/2014/01/03/205150.htmlhttp://www.shnenglu.com/tankzhouqiang/comments/205150.htmlhttp://www.shnenglu.com/tankzhouqiang/archive/2014/01/03/205150.html#Feedback0http://www.shnenglu.com/tankzhouqiang/comments/commentRss/205150.htmlhttp://www.shnenglu.com/tankzhouqiang/services/trackbacks/205150.html

鍛ㄥ己 2014-01-03 21:17 鍙戣〃璇勮
]]>
python functools wraps (杞?http://www.shnenglu.com/tankzhouqiang/archive/2013/11/05/204102.html鍛ㄥ己鍛ㄥ己Tue, 05 Nov 2013 12:40:00 GMThttp://www.shnenglu.com/tankzhouqiang/archive/2013/11/05/204102.htmlhttp://www.shnenglu.com/tankzhouqiang/comments/204102.htmlhttp://www.shnenglu.com/tankzhouqiang/archive/2013/11/05/204102.html#Feedback0http://www.shnenglu.com/tankzhouqiang/comments/commentRss/204102.htmlhttp://www.shnenglu.com/tankzhouqiang/services/trackbacks/204102.htmlWhen you use a decorator, you're replacing one function with another. In other words, if you have a decorator

  1. def logged(func):  
  2.     def with_logging(*args, **kwargs):  
  3.         print func.__name__ + " was called"  
  4.         return func(*args, **kwargs)  
  5.     return with_logging  

then when you say

  1. @logged  
  2. def f(x):  
  3.    """does some math"""  
  4.    return x + x * x  

it's exactly the same as saying

  1. def f(x):  
  2.     """does some math"""  
  3.     return x + x * x  
  4. f = logged(f)  

and your function f is replaced with the function with_logging. Unfortunately, this means that if you then say

  1. print f.__name__  

it will print with_logging because that's the name of your new function. In fact, if you look at the docstring for f, it will be blank because with_logging has no docstring, and so the docstring you wrote won't be there anymore. Also, if you look at the pydoc result for that function, it won't be listed as taking one argument x; instead it'll be listed as taking *args and **kwargs because that's what with_logging takes.

If using a decorator always meant losing this information about a function, it would be a serious problem. That's why we have functools.wraps. This takes a function used in a decorator and adds the functionality of copying over the function name, docstring, arguments list, etc. And since wraps is itself a decorator, the following code does the correct thing:

  1. from functools import wraps  
  2. def logged(func):  
  3.     @wraps(func)  
  4.     def with_logging(*args, **kwargs):  
  5.         print func.__name__ + " was called"  
  6.         return func(*args, **kwargs)  
  7.     return with_logging  
  8.  
  9. @logged  
  10. def f(x):  
  11.    """does some math"""  
  12.    return x + x * x  
  13.   
  14. print f.__name__  # prints 'f'  
  15. print f.__doc__   # prints 'does some math'  


    杞嚜http://blog.csdn.net/wanghai__/article/details/7078792



鍛ㄥ己 2013-11-05 20:40 鍙戣〃璇勮
]]>
Oracle Redo Log 鏈哄埗 灝忕粨錛堣漿杞斤級http://www.shnenglu.com/tankzhouqiang/archive/2013/01/08/197126.html鍛ㄥ己鍛ㄥ己Tue, 08 Jan 2013 11:20:00 GMThttp://www.shnenglu.com/tankzhouqiang/archive/2013/01/08/197126.htmlhttp://www.shnenglu.com/tankzhouqiang/comments/197126.htmlhttp://www.shnenglu.com/tankzhouqiang/archive/2013/01/08/197126.html#Feedback0http://www.shnenglu.com/tankzhouqiang/comments/commentRss/197126.htmlhttp://www.shnenglu.com/tankzhouqiang/services/trackbacks/197126.html闃呰鍏ㄦ枃

鍛ㄥ己 2013-01-08 19:20 鍙戣〃璇勮
]]>
銆愭搷浣滅郴緇熴慙inux鎬ц兘鐩戞帶鈥斺擟PU銆丮emory銆両O銆丯etwork錛堣漿杞斤級http://www.shnenglu.com/tankzhouqiang/archive/2012/12/26/196699.html鍛ㄥ己鍛ㄥ己Wed, 26 Dec 2012 14:02:00 GMThttp://www.shnenglu.com/tankzhouqiang/archive/2012/12/26/196699.htmlhttp://www.shnenglu.com/tankzhouqiang/comments/196699.htmlhttp://www.shnenglu.com/tankzhouqiang/archive/2012/12/26/196699.html#Feedback0http://www.shnenglu.com/tankzhouqiang/comments/commentRss/196699.htmlhttp://www.shnenglu.com/tankzhouqiang/services/trackbacks/196699.html闃呰鍏ㄦ枃

鍛ㄥ己 2012-12-26 22:02 鍙戣〃璇勮
]]>
top鍛戒護(杞澆)http://www.shnenglu.com/tankzhouqiang/archive/2012/08/28/188551.html鍛ㄥ己鍛ㄥ己Tue, 28 Aug 2012 12:42:00 GMThttp://www.shnenglu.com/tankzhouqiang/archive/2012/08/28/188551.htmlhttp://www.shnenglu.com/tankzhouqiang/comments/188551.htmlhttp://www.shnenglu.com/tankzhouqiang/archive/2012/08/28/188551.html#Feedback0http://www.shnenglu.com/tankzhouqiang/comments/commentRss/188551.htmlhttp://www.shnenglu.com/tankzhouqiang/services/trackbacks/188551.html闃呰鍏ㄦ枃

鍛ㄥ己 2012-08-28 20:42 鍙戣〃璇勮
]]>
鎶宸э細澶氬叡浜姩鎬佸簱涓悓鍚嶅璞¢噸澶嶆瀽鏋勯棶棰樼殑瑙e喅鏂規硶(杞澆)http://www.shnenglu.com/tankzhouqiang/archive/2012/03/02/166985.html鍛ㄥ己鍛ㄥ己Fri, 02 Mar 2012 08:04:00 GMThttp://www.shnenglu.com/tankzhouqiang/archive/2012/03/02/166985.htmlhttp://www.shnenglu.com/tankzhouqiang/comments/166985.htmlhttp://www.shnenglu.com/tankzhouqiang/archive/2012/03/02/166985.html#Feedback0http://www.shnenglu.com/tankzhouqiang/comments/commentRss/166985.htmlhttp://www.shnenglu.com/tankzhouqiang/services/trackbacks/166985.htmlLinux 鏀寔鐨勫叡浜▼搴忓簱錛?strong>lib*.so錛夋妧鏈笉浠呰兘澶熸湁鏁堝埄鐢ㄧ郴緇熻祫婧愶紝鑰屼笖榪樺紼嬪簭璁捐甯︽潵浜嗗緢澶х殑渚垮埄鎬с侀氱敤鎬х瓑錛屽洜姝よ鍚勭綰у埆鐨勫簲鐢ㄧ郴緇熷箍娉涢噰鐢ㄣ?鍔ㄦ侀摼鎺ョ殑鍏變韓搴撴槸鍦ㄥ姞杞藉簲鐢ㄧ▼搴忔椂琚姞杞界殑錛岃屼笖瀹冧笌搴旂敤紼嬪簭鏄湪榪愯鏃剁粦瀹氱殑錛氶氳繃鍔ㄦ侀摼鎺ュ櫒錛屽皢鍔ㄦ佸叡浜簱鏄犲皠榪涘簲鐢ㄧ▼搴忕殑鍙墽琛屽唴瀛樹腑錛堝姩鎬侀摼鎺ワ級錛涘湪鍚姩搴旂敤紼嬪簭鏃訛紝鍔ㄦ佽杞藉櫒灝嗘墍闇鐨勫叡浜洰鏍囧簱鏄犲皠鍒板簲鐢ㄧ▼搴忕殑鍐呭瓨錛堝姩鎬佽杞斤級銆?/p>

鍦ㄩ氬父鎯呭喌涓嬶紝鍏變韓搴撻兘鏄氳繃浣跨敤闄勫姞閫夐」 -fpic 鎴?nbsp;-fPIC 榪涜緙栬瘧錛屼粠鐩爣浠g爜浜х敓浣嶇疆鏃犲叧鐨勪唬鐮侊紙Position Independent Code錛孭IC錛夛紝浣跨敤 -shared閫夐」灝嗙洰鏍囦唬鐮佹斁榪涘叡浜洰鏍囧簱涓備綅緗棤鍏充唬鐮侀渶瑕佽兘澶熻鍔犺澆鍒頒笉鍚岃繘紼嬬殑涓嶅悓鍦板潃錛屽茍涓旇兘寰椾互姝g‘鐨勬墽琛岋紝鏁呭叾浠g爜瑕佺粡榪囩壒鍒殑緙栬瘧澶勭悊錛氫綅緗棤鍏充唬鐮侊紙PIC錛夊甯擱噺鍜屽嚱鏁板叆鍙e湴鍧鐨勬搷浣滈兘鏄噰鐢ㄥ熀浜庡熀瀵勫瓨鍣紙base register錛塀ASE+ 鍋忕Щ閲忕殑鐩稿鍦板潃鐨勫鍧鏂瑰紡銆傚嵆浣跨▼搴忚瑁呰澆鍒板唴瀛樹腑鐨勪笉鍚屽湴鍧錛屽嵆 BASE 鍊間笉鍚岋紝鑰屽亸縐婚噺鏄笉鍙樼殑錛屾墍浠ョ▼搴忎粛鐒跺彲浠ユ壘鍒版紜殑鍏ュ彛鍦板潃鎴栬呭父閲忋?/p>

鐒惰岋紝褰撳簲鐢ㄧ▼搴忛摼鎺ヤ簡澶氫釜鍏變韓搴擄紝濡傛灉鍦ㄨ繖浜涘叡浜簱涓紝瀛樺湪鐩稿悓浣滅敤鍩熻寖鍥寸殑鍚屽悕闈欐佹垚鍛樺彉閲忔垨鑰呭悓鍚?( 闈為潤鎬?) 鍏ㄥ眬鍙橀噺錛岄偅涔堝綋紼嬪簭璁塊棶瀹岄潤鎬佹垚鍛樺彉閲忔垨鍏ㄥ眬鍙橀噺緇撴潫鏋愭瀯鏃訛紝鐢變簬鏌愬唴瀛樺潡鐨?double free 浼氬鑷?core dump錛岃繖鏄敱浜?Linux 緙栬瘧鍣ㄧ殑緙洪櫡閫犳垚鐨勩?/p>

搴旂敤鍦烘櫙鍘熷瀷

璇ラ棶棰樻簮浜庣瑪鑰呮墍浠庝簨鐨勫紑鍙戦」鐩細IBM Tivoli Workload Scheduler (TWS) LoadLeveler銆?strong>LoadLeveler鏄?nbsp;IBM鍦ㄩ珮鎬ц兘璁$畻錛?strong>High Performance Computing錛孒PC錛夐鍩熺殑涓嬈句綔涓氳皟搴﹁蔣浠躲傚畠涓昏鍒嗕負涓や釜澶х殑妯″潡錛屽垎鍒槸璋冨害妯″潡錛坰cheduler錛夊拰璧勬簮綆$悊妯″潡錛坮esource manger錛夈?涓や釜妯″潡涓垎鍒惈鏈夊叧浜庨厤緗鐞嗗姛鑳界殑鍏變韓搴擄紝鐢變簬鏌愪簺閰嶇疆綆$悊閫夐」涓轟袱妯″潡鎵鍏卞悓閲囩敤錛屾墍浠ヤ袱妯″潡涔嬮棿鍏變韓浜嗛儴鍒嗘簮鏂囦歡浠g爜錛屽叾涓寘鍚湁鍚屽悕鐨勭被闈欐佹垚鍛樸?/p>

鍙互閫氳繃浠ヤ笅綆鍗曠殑妯″瀷榪涜鎻忚堪錛?/p>
鍥?1. 搴旂敤鍦烘櫙
鍥劇墖紺轟緥 

瀵瑰簲鐨勫悇妯″潡浠g爜鐗囨濡備笅鍥炬墍紺猴細


鍥?2. 搴旂敤鍦烘櫙妯℃嫙浠g爜
鍥劇墖紺轟緥 

鍏朵腑錛宼est.c 鏄富紼嬪簭錛屽寘鍚湁涓や釜澶存枃浠訛細api1.h 涓?api2.h錛涘ご鏂囦歡 api1.h 鍖呭惈澶存枃浠?lib1/lib.h 鍜屼竴鍔熻兘鍑芥暟 func_api1()錛宎pi2.h 鍖呭惈澶存枃浠?lib2/lib.h 鍜屼竴鍔熻兘鍑芥暟 func_api2()錛涚洰褰?lib1 鍜?lib2 涓嬬殑婧愭枃浠跺垎鍒紪璇戠敓鎴愬叡浜簱 lib1.so 鍜?lib2.so銆傚悓鏃訛紝澶存枃浠?lib1/lib.h 涓?lib2/lib.h 閾炬帴鍒板悓涓鍏變韓鏂囦歡 lib.h銆傚湪鏂囦歡 lib.h 涓畾涔夋湁涓闈欐佹垚鍛樺彉閲?#8220;static std::vector<int> vec_int”銆?/p>

鍥為〉棣?/a>

鍔熻兘鍑芥暟涓庡悇闈欐佹垚鍛樺嚱鏁頒唬鐮佹竻鍗?/span>

鍔熻兘鍑芥暟 func_api1() 涓?func_api2() 鐨勫疄鐜扮被浼鹼紝閫氳繃璋冪敤闈欐佹垚鍛樺嚱鏁拌揪鍒拌闂潤鎬佹垚鍛樺彉閲?nbsp;vec_int鐨勭洰鐨勶細


娓呭崟 1. 鍔熻兘鍑芥暟 func_api1(int)
          void func_api1(int i) {      printf("%s.\n", __FILE__);       A::set(i);      A::print();      return;   }      

闈欐佹垚鍛樺嚱鏁?A::set() 涓?A::print() 鐨勫疄鐜板涓嬶細


娓呭崟 2. 闈欐佹垚鍛樺嚱鏁?A::set(int)
          void A::set(int num) {      vec_int.clear();      for (int i = 0; i < num; i++) {          vec_int.push_back(i);      }      return;   }      


娓呭崟 3. 闈欐佹垚鍛樺嚱鏁?A::print()
          void A::print() {      for (int i = 0; i < vec_int.size(); i++) {          printf("vec_int[%d] = %d, addr: %p.\n", i, vec_int[i], &vec_int[i]);      }      printf("vec_int addr: %p.\n", &vec_int);      return;   }      

A::set() 瀵歸潤鎬佹垚鍛?nbsp;vec_int榪涜璧嬪兼搷浣滐紝鑰?A::print() 鍒欐墦鍗板叾涓殑鍊間笌褰撳墠欏圭殑鍐呭瓨鍦板潃銆?/p>

鍥為〉棣?/a>

榪愯緇撴灉

濡傛灉涓や釜鍏變韓搴撴槸閫氳繃閫夐」 -fpic鎴?nbsp;-fPIC緙栬瘧鐨勮瘽錛岃繍琛岀▼搴?test錛岃緭鍑哄涓嬶細


娓呭崟 4. 閫夐」 -fPIC 鐨勬祴璇曠粨鏋?/strong>
          $ export LD_LIBRARY_PATH=./:$LD_LIBRARY_PATH   $ g++ -g -o lib1.so -fPIC-rdynamic -shared lib1/lib.c   $ g++ -g -o lib2.so -fPIC-rdynamic -shared lib2/lib.c   $ g++ -g -o test -L./ -l1 -l2 test.c   $ ./test  api1.h.   vec_int[0] = 0, addr: 0x9cbf028.   vec_int[1] = 1, addr: 0x9cbf02c.   vec_int[2] = 2, addr: 0x9cbf030.   vec_int[3] = 3, addr: 0x9cbf034.   vec_int addr: 0xe89228.   *** glibc detected *** ./test: double free or corruption (fasttop): 0x09cbf028***   ======= Backtrace:=========   /lib/libc.so.6[0x2b2b16]   /lib/libc.so.6(cfree+0x90)[0x2b6030]   /usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0x5d1731]   ./lib1.so(_ZN9__gnu_cxx13new_allocatorIiE10deallocateEPij+0x1d)[0xe88417]         ./lib1.so(_ZNSt12_Vector_baseIiSaIiEE13_M_deallocateEPij+0x33)[0xe88451]         ./lib1.so(_ZNSt12_Vector_baseIiSaIiEED2Ev+0x42)[0xe8849a]         ./lib1.so(_ZNSt6vectorIiSaIiEED1Ev+0x60)[0xe8850c]  ./lib2.so[0x961d6c]   /lib/libc.so.6(__cxa_finalize+0xa9)[0x275c79]   ./lib2.so[0x961c34]   ./lib2.so[0x962d3c]   /lib/ld-linux.so.2[0x23a7de]   /lib/libc.so.6(exit+0xe9)[0x2759c9]   /lib/libc.so.6(__libc_start_main+0xe4)[0x25fdf4]   ./test(__gxx_personality_v0+0x45)[0x80484c1]   ======= Memory map:========   ......   00960000-00963000 r-xp 00000000 00:1b 7668734    ./lib2.so   00963000-00964000 rwxp 00003000 00:1b 7668734    ./lib2.so   00970000-00971000 r-xp 00970000 00:00 0          [vdso]   00e86000-00e89000 r-xp 00000000 00:1b 7668022    ./lib1.so   00e89000-00e8a000 rwxp 00003000 00:1b 7668022    ./lib1.so  08048000-08049000 r-xp 00000000 00:1b 7668748    ./test   08049000-0804a000 rw-p 00000000 00:1b 7668748    ./test   09cbf000-09ce0000 rw-p 09cbf000 00:00 0          [heap]  ......   Abort(coredump)   $      

浠庣▼搴忕殑杈撳嚭鐩磋鐨勭湅鍒幫紝core 浜х敓鏄敱浜庡爢鍐呭瓨鍖哄煙錛?strong>09cbf000-09ce0000錛変腑璧峰鍦板潃涓?nbsp;0x09cbf028鐨勫唴瀛樺尯琚噴鏀句簡涓ゆ瀵艱嚧鐨勶紝璇ュ湴鍧姝e紡闈欐佹垚鍛樺彉閲?nbsp;vec_int鐨勭涓涓厓绱犵殑鍦板潃銆?/p>

涓轟粈涔堜細鍑虹幇鍚屼竴鍧楀唴瀛樺尯錛岃閲婃斁涓ゆ鐨勬儏褰㈠憿錛?/p>

鍥為〉棣?/a>

鍘熷洜鍒嗘瀽

鎴戜滑鐭ラ亾錛岄潤鎬佹垚鍛樺彉閲忎笌鍏ㄥ眬鍙橀噺綾諱技錛岄兘閲囩敤浜嗛潤鎬佸瓨鍌ㄦ柟寮忋傚浜庡姞浜嗛夐」 -fpic鎴?nbsp;-fPIC鐨勫叡浜簱錛岃繖浜涘彉閲忕殑鍦板潃閮藉瓨鏀懼湪璇ュ叡浜簱鐨勫叏灞鍋忕Щ琛紙Global Offset Table錛孏OT錛変腑銆?/p>

閫氳繃 objdump鎴栬?nbsp;readelf鍛戒護鍒嗘瀽鍏變韓搴?nbsp;lib1.so錛岀粨鏋滃涓嬶細


娓呭崟 5. objdump 鍒嗘瀽鍏變韓搴?lib1.so 鐨勮緭鍑?/strong>
          $ objdump -x -R lib1.so    lib1.so:     file format elf32-i386   ......   Sections:   Idx Name          Size      VMA       LMA       File off  Algn    0 .gnu.hash     000001e8  000000d4  000000d4  000000d4  2**2                    CONTENTS, ALLOC, LOAD, READONLY, DATA   ......   18 .dynamic      000000d8  0000301c  0000301c  0000301c  2**2                    CONTENTS, ALLOC, LOAD, DATA   19 .got          00000014  000030f4  000030f4  000030f4  2**2                   CONTENTS, ALLOC, LOAD, DATA   20 .got.plt      00000114  00003108  00003108  00003108  2**2                    CONTENTS, ALLOC, LOAD, DATA   ......   DYNAMIC RELOCATION RECORDS   OFFSET   TYPE              VALUE   ......   000030f4 R_386_GLOB_DAT    __gmon_start__   000030f8 R_386_GLOB_DAT    _Jv_RegisterClasses   000030fc R_386_GLOB_DAT    _ZN1A7vec_intE  00003104 R_386_GLOB_DAT    __cxa_finalize   ......      


娓呭崟 6. readelf 鍒嗘瀽鍏變韓搴?lib1.so 鐨勮緭鍑?/strong>
          $ objdump -x -R lib1.so    lib1.so:     file format elf32-i386   ......   Sections:   Idx Name          Size      VMA       LMA       File off  Algn    0 .gnu.hash     000001e8  000000d4  000000d4  000000d4  2**2                    CONTENTS, ALLOC, LOAD, READONLY, DATA   ......   18 .dynamic      000000d8  0000301c  0000301c  0000301c  2**2                    CONTENTS, ALLOC, LOAD, DATA   19 .got          00000014  000030f4  000030f4  000030f4  2**2                   CONTENTS, ALLOC, LOAD, DATA   20 .got.plt      00000114  00003108  00003108  00003108  2**2                    CONTENTS, ALLOC, LOAD, DATA   ......   DYNAMIC RELOCATION RECORDS   OFFSET   TYPE              VALUE   ......   000030f4 R_386_GLOB_DAT    __gmon_start__   000030f8 R_386_GLOB_DAT    _Jv_RegisterClasses   000030fc R_386_GLOB_DAT    _ZN1A7vec_intE  00003104 R_386_GLOB_DAT    __cxa_finalize   ......      

浠庝笂闈袱涓懡浠ょ殑杈撳嚭緇撴灉涓彲浠ョ湅鍑猴紝鍏變韓搴?nbsp;lib1.so涓?nbsp;GOT孌電殑璧峰鍐呭瓨鍦板潃涓?nbsp;000030f4錛屽ぇ灝忎負 20 瀛楄妭 (0x14)錛涢潤鎬佹垚鍛樺彉閲?nbsp;vec_int鍦ㄥ叡浜簱 lib1.so涓殑璧峰鍋忕Щ鍦板潃涓?nbsp;000030fc銆傛樉鐒訛紝vec_int浣嶄簬璇ュ叡浜簱鐨?nbsp;GOT孌靛唴銆?/p>

褰撳簲鐢ㄧ▼搴忓悓鏃墮摼鎺?nbsp;lib1.so鍜?nbsp;lib2.so鏃訛紝鍚屽悕闈欐佹垚鍛樺彉閲?nbsp;vec_int鍒嗗埆浣嶄簬鍏跺叡浜簱鐨?nbsp;GOT鍖恒傚綋紼嬪簭榪愯鏃訛紝緋葷粺浠庣鍙瘋〃涓煡鎵懼茍瑁呰澆鏋勯犱竴浠?nbsp;vec_int鏁版嵁錛岃繖鐐逛粠紼嬪簭榪愯鐨勮緭鍑虹粨鏋滐紙娓呭崟 4錛夌殑“Backtrace”閮ㄥ垎鍙互鐪嬪埌錛氬彧鏈?nbsp;lib1.so涓殑闈欐佹垚鍛樺彉閲忚瑁呰澆鏋勯狅紱鍚屾椂錛岄氳繃鍐呭瓨鏄犲皠錛?strong>Memory map錛夐儴鍒嗭紙娓呭崟 4錛夛紝鍙互瑙傚療鍒?nbsp;vec_int瀵硅薄鐨勫湴鍧 0xe89228姝eソ澶勫湪涓哄叡浜簱 lib1.so鍒嗛厤鐨勫彲璇誨唴瀛樺尯 00e89000-00e8a000涓細

        00e89000-00e8a000 rwxp 00003000 00:1b 7668022    ./lib1.so

鐒跺悗錛屽綋紼嬪簭緇撴潫鏃訛紝鍗村璇ュ彉閲忚繘琛屼簡涓ゆ鏋愭瀯鎿嶄綔錛岄氳繃 gdb鍒嗘瀽 core 鏂囦歡錛?/p>
娓呭崟 7. core 鏂囦歡鍒嗘瀽緇撴灉
          $ gdb ./test core.28440 ……  Core was generated by `./test'.   Program terminated with signal 6, Aborted.   #0  0x00970402 in __kernel_vsyscall ()   (gdb)   (gdb) where   #0  0x00970402 in __kernel_vsyscall ()   #1  0x00272d10 in raise () from /lib/libc.so.6   #2  0x00274621 in abort () from /lib/libc.so.6   #3  0x002aae5b in __libc_message () from /lib/libc.so.6   #4  0x002b2b16 in _int_free () from /lib/libc.so.6   #5  0x002b6030 in free () from /lib/libc.so.6   #6  0x005d1731 in operator delete () from /usr/lib/libstdc++.so.6   #7  0x00e88417 in __gnu_cxx::new_allocator<int>::deallocate       (this=0xe89228, __p=0x9cbf028)      at /usr/lib/gcc/i386-redhat-linux/.../ext/new_allocator.h:94   #8  0x00e88451 in std::_Vector_base<int, ... (this=0xe89228, __p=0x9cbf028, __n=4)      at /usr/lib/gcc/.../include/c++/4.1.2/bits/stl_vector.h:133   #9  0x00e8849a in ~_Vector_base (this=0xe89228)      at /usr/lib/gcc/.../include/c++/4.1.2/bits/stl_vector.h:119   #10 0x00e8850cin ~vector (this=0xe89228) at /usr/lib/gcc/.../stl_vector.h:272   #11 0x00961d6c in __tcf_0 () at lib2/lib.c:3   #12 0x00275c79 in __cxa_finalize () from /lib/libc.so.6   #13 0x00961c34 in __do_global_dtors_aux () from ./lib2.so   #14 0x00962d3c in _fini () from ./lib2.so  #15 0x0023a7de in _dl_fini () from /lib/ld-linux.so.2   #16 0x002759c9 in exit () from /lib/libc.so.6   #17 0x0025fdf4 in __libc_start_main () from /lib/libc.so.6   #18 0x080484c1 in _start ()   (gdb)      

浠庢竻鍗?7 涓彲浠ョ湅鍑猴紝浠庡撫 #14 寮濮嬶紝紼嬪簭榪涜 lib2.so涓殑鏋愭瀯鎿嶄綔錛岀洿鍒?#11錛岄兘榪愯鍦?nbsp;lib2.so涓紝褰撹繘鍏ュ撫 #10 鏃訛紝榪涜鍙橀噺鏋愭瀯鏃訛紝鍏跺湴鍧涓?nbsp;0x00e8850c錛岃鍦板潃涓殑瀵硅薄鏄▼搴忓惎鍔ㄦ椂鐢卞叡浜簱 lib1.so瑁呰澆鏋勯犲嚭鏉ョ殑錛堟竻鍗?1錛夛細

        ./lib1.so(_ZNSt6vectorIiSaIiEED1Ev+0x60)[0xe8850c]

褰撶▼搴忕粨鏉熸椂錛岃繍琛屽簱 glibc媯嫻嬪埌鍏變韓搴?nbsp;lib2.so鏋愭瀯浜嗗茍闈炵敱鍏舵瀯閫犵殑瀵硅薄錛屽鑷翠簡 core dump銆?/p>

榪欑鎯呭喌涓嬶紝濡傛灉鏇挎崲浣跨敤閫夐」 -fpie鎴?nbsp;-fPIE錛屾搷浣滄楠や笌榪愯緇撴灉濡備笅鎵紺猴細


娓呭崟 8. 閫夐」 -fPIE 鐨勬祴璇曠粨鏋?/strong>
          $ export LD_LIBRARY_PATH=./:$LD_LIBRARY_PATH   $ g++ -g -o lib1.so -fPIE-rdynamic -shared lib1/lib.c   $ g++ -g -o lib2.so -fPIE-rdynamic -shared lib2/lib.c   $ g++ -g -pie -o test -L./ -l1 -l2 test.c   $ ./test  api1.h.   vec_int[0] = 0, addr: 0x80e3028.   vec_int[1] = 1, addr: 0x80e302c.   vec_int[2] = 2, addr: 0x80e3030.   vec_int[3] = 3, addr: 0x80e3034.   vec_int addr: 0x75e224.   $      

紼嬪簭榪愯緇撴灉絎﹀悎鏈熸湜騫舵甯哥粨鏉熴?/p>

榪欐槸鍥犱負錛屽綋浣跨敤閫夐」 -fpie鎴?nbsp;-fPIE鏃訛紝鐢熸垚鐨勫叡浜簱涓嶄細涓洪潤鎬佹垚鍛樺彉閲忔垨鍏ㄥ眬鍙橀噺鍦?nbsp;GOT涓垱寤哄搴旂殑鏉$洰錛堥氳繃 objdump鎴?strong>readelf鍛戒護鍙互鏌ョ湅錛屾澶勪笉鍐嶈禈榪幫級錛屼粠鑰岄伩鍏嶄簡鐢變簬闈欐佸璞?#8220;鏋勯犱竴嬈★紝鏋愭瀯涓ゆ”鑰屽鍚屼竴鍐呭瓨鍖哄煙閲婃斁涓ゆ寮曡搗鐨勭▼搴?core dump銆?/p>

閫夐」 -fpie鍜?nbsp;-fPIE涓?nbsp;-fpic鍙?nbsp;-fPIC鐨勭敤娉曞緢鐩鎬技錛屽尯鍒湪浜庡墠鑰呮繪槸灝嗙敓鎴愮殑浣嶇疆鏃犲叧浠g爜鐪嬩綔鏄睘浜庣▼搴忔湰韜紝騫剁洿鎺ラ摼鎺ヨ繘璇ュ彲鎵ц紼嬪簭錛岃岄潪瀛樺叆鍏ㄥ眬鍋忕Щ琛?nbsp;GOT涓紱榪欐牱錛屽浜庡悓鍚嶇殑闈欐佹垨鍏ㄥ眬瀵硅薄鐨勮闂紝鍏舵瀯閫犱笌鏋愭瀯鎿嶄綔灝嗕繚鎸佷竴涓瀵瑰簲銆?/p>

鍥為〉棣?/a>

緇撴潫璇?/span>

閫氳繃浣跨敤閫夐」 -fpie鎴?nbsp;-fPIE浠f浛 -fpic鎴栬?nbsp;-fPIC錛屼嬌寰楃敓鎴愮殑鍏變韓搴撲笉浼氫負闈欐佹垚鍛樺彉閲忔垨鍏ㄥ眬鍙橀噺鍦?nbsp;GOT涓垱寤哄搴旂殑鏉$洰錛屽悓鏃朵篃灝遍伩鍏嶄簡閽堝鍚屽悕闈欐佸璞?#8220;鏋勯犱竴嬈★紝鏋愭瀯涓ゆ”鐨勪笉褰撴搷浣溿?br />
杞嚜錛?a >http://www.ibm.com/developerworks/cn/linux/l-cn-sdlstatic/ 







鍛ㄥ己 2012-03-02 16:04 鍙戣〃璇勮
]]>
CppUnit蹇熷叆闂紙杞澆錛?/title><link>http://www.shnenglu.com/tankzhouqiang/archive/2012/03/01/166911.html</link><dc:creator>鍛ㄥ己</dc:creator><author>鍛ㄥ己</author><pubDate>Thu, 01 Mar 2012 12:25:00 GMT</pubDate><guid>http://www.shnenglu.com/tankzhouqiang/archive/2012/03/01/166911.html</guid><wfw:comment>http://www.shnenglu.com/tankzhouqiang/comments/166911.html</wfw:comment><comments>http://www.shnenglu.com/tankzhouqiang/archive/2012/03/01/166911.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/tankzhouqiang/comments/commentRss/166911.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/tankzhouqiang/services/trackbacks/166911.html</trackback:ping><description><![CDATA[<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">綆浠?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">嫻嬭瘯鏄蔣浠跺紑鍙戣繃紼嬩腑鏋佸叾閲嶈鐨勪竴鐜紝璇﹀敖鍛ㄥ瘑鐨勬祴璇曡兘澶熷噺灝戣蔣浠禕UG錛屾彁楂樿蔣浠跺搧璐ㄣ傛祴璇曞寘鎷崟鍏冩祴璇曘佺郴緇熸祴璇曠瓑銆傚叾涓崟鍏冩祴璇曟槸鎸囬拡瀵硅蔣浠跺姛鑳藉崟鍏冩墍浣滅殑嫻嬭瘯錛岃繖閲岀殑鍔熻兘鍗曞厓鍙互鏄竴涓被鐨勫睘鎬ф垨鑰呮柟娉曪紝嫻嬭瘯鐨勭洰鐨勬槸鐪嬭繖浜涘熀鏈崟鍏冩槸鍚﹀伐浣滄甯搞傜敱浜庡崟鍏冩祴璇曠殑鍐呭寰堝熀紜錛屽洜姝ゅ彲浠ョ湅浣滄槸嫻嬭瘯宸ヤ綔鐨勭涓鐜紝璇ラ」宸ヤ綔涓鑸敱寮鍙戜漢鍛樿嚜琛屽畬鎴愩傚鏋滄潯浠跺厑璁革紝鍗曞厓嫻嬭瘯浠g爜鐨勫紑鍙戝簲涓庣▼搴忎唬鐮佺殑寮鍙戝悓姝ヨ繘琛屻?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">铏界劧涓嶅悓紼嬪簭鐨勫崟鍏冩祴璇曚唬鐮佷笉灝界浉鍚岋紝浣嗘祴璇曚唬鐮佺殑妗嗘灦鍗撮潪甯哥浉浼鹼紝浜庢槸渚垮嚭鐜頒簡涓浜涘崟鍏冩祴璇曠被搴擄紝CppUnit渚挎槸鍏朵腑涔嬩竴銆?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">CppUnit鏄疿Unit涓殑涓鍛橈紝XUnit鏄竴涓ぇ瀹舵棌錛岃繕鍖呮嫭JUnit鍜孭ythonUnit絳夈侰ppUnit綆鍗曞疄鐢紝瀛︿範鍜屼嬌鐢ㄨ搗鏉ラ兘寰堟柟渚匡紝緗戜笂宸叉湁涓浜涙枃绔犲鍏朵綔浠嬬粛錛屼絾鏈枃鏇寸潃閲嶄簬璁茶В鍏朵腑鐨勫熀鏈蹇靛拰浣跨敤鏂規硶錛屼互甯姪鍒濇鎺ヨЕCppUnit鐨勪漢鍛樺揩閫熷叆闂ㄣ?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">瀹夎</p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鐩墠錛孋ppUnit鐨勬渶鏂扮増鏈槸1.10.2錛屼綘鍙互浠庝笅闈㈠湴鍧鑾峰彇錛?/p><a style="color: #336699; text-decoration: none; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">http://sourceforge.net/projects/cppunit</a><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">瑙e帇鍚庯紝浣犲彲浠ョ湅鍒癈ppUnit鍖呭惈濡備笅鐩綍錛?/p><pre style="word-wrap: break-word; white-space: normal; line-height: 26px; text-align: left; background-color: #f5f5f5; color: green; ">config錛?閰嶇疆鏂囦歡 contrib錛?contribution錛屽叾浠栦漢璐$尞鐨勫鍥翠唬鐮?doc錛?鏂囨。錛岄渶瑕侀氳繃doxygen宸ュ叿鐢熸垚錛屼篃鍙互鐩存帴浠巗ourceforge绔欑偣涓婁笅杞芥墦鍖呭ソ鐨勬枃妗?examples錛氱ず渚嬩唬鐮?include錛?澶存枃浠?lib錛?瀛樻斁緙栬瘧濂界殑搴?src錛?婧愭枃浠訛紝浠ュ強緙栬瘧搴撶殑宸ョ▼絳?/pre><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鐒跺悗鎵撳紑src鐩綍涓嬬殑CppUnitLibraries宸ョ▼錛屾墽琛宐uild/batch build錛岀紪璇戞垚鍔熺殑璇濓紝鐢熸垚鐨勫簱鏂囦歡灝嗚鎷瘋礉鍒發ib鐩綍涓嬨?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">浣犱篃鍙互鏍規嵁闇瑕侀夋嫨鎵闇鐨勯」鐩繘琛岀紪璇戯紝鍏朵腑欏圭洰cppunit涓洪潤鎬佸簱錛宑ppunit_dll涓哄姩鎬佸簱錛岀敓鎴愮殑搴撴枃浠朵負錛?/p><pre style="word-wrap: break-word; white-space: normal; line-height: 26px; text-align: left; background-color: #f5f5f5; color: green; ">cppunit.lib錛?闈欐佸簱release鐗?cppunitd.lib錛?闈欐佸簱debug鐗?cppunit_dll.lib錛?鍔ㄦ佸簱release鐗?cppunitd_dll.lib錛氬姩鎬佸簱debug鐗?/pre><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">瑕佷嬌鐢–ppUnit錛岃繕寰楄緗ソ澶存枃浠跺拰搴撴枃浠惰礬寰勶紝浠C6涓轟緥錛岄夋嫨Tools/Options/Directories錛屽湪Include files鍜孡ibrary files涓垎鍒坊鍔?CppUnitPath%/include鍜?CppUnitPath%/lib錛屽叾涓?CppUnitPath%琛ㄧずCppUnit鎵鍦ㄨ礬寰勩?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鍋氬ソ鍑嗗宸ヤ綔鍚庯紝鎴戜滑灝卞彲浠ョ紪鍐欒嚜宸辯殑鍗曞厓嫻嬭瘯浠g爜浜嗐傞渶璇存槑鐨勬槸錛孋ppUnit鎵鐢ㄧ殑鍔ㄦ佽繍琛屾湡搴撳潎涓哄綰跨▼鍔ㄦ佸簱錛屽洜姝や綘鐨勫崟鍏冩祴璇曠▼搴忎篃寰椾嬌鐢ㄧ浉搴旇緗紝鍚﹀垯浼氬彂鐢熷啿紿併?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">姒傚康</p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鍦ㄤ嬌鐢ㄤ箣鍓嶏紝鎴戜滑鏈夊繀瑕佽璇嗕竴涓婥ppUnit涓殑涓昏綾伙紝褰撶劧浣犱篃鍙互鍏堢湅鍚庨潰鐨勪緥瀛愶紝閬囧埌闂鍐嶅洖榪囧ご鏉ョ湅榪欎竴鑺傘?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">CppUnit鏍稿績鍐呭涓昏鍖呮嫭鍏釜鏂歸潰錛?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">1. 嫻嬭瘯瀵硅薄錛圱est錛孴estFixture錛?..錛夛細鐢ㄤ簬寮鍙戞祴璇曠敤渚嬶紝浠ュ強瀵規祴璇曠敤渚嬭繘琛岀粍緇囩鐞嗐?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">2. 嫻嬭瘯緇撴灉錛圱estResult錛夛細澶勭悊嫻嬭瘯鐢ㄤ緥鎵ц緇撴灉銆俆estResult涓庝笅闈㈢殑TestListener閲囩敤鐨勬槸瑙傚療鑰呮ā寮忥紙Observer Pattern錛夈?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">3. 嫻嬭瘯緇撴灉鐩戝惉鑰咃紙TestListener錛夛細TestListener浣滀負TestResult鐨勮瀵熻咃紝鎷呬換瀹為檯鐨勭粨鏋滃鐞嗚鑹層?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">4. 緇撴灉杈撳嚭錛圤utputter錛夛細灝嗙粨鏋滆繘琛岃緭鍑猴紝鍙互鍒跺畾涓嶅悓鐨勮緭鍑烘牸寮忋?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">5. 瀵硅薄宸ュ巶錛圱estFactory錛夛細鐢ㄤ簬鍒涘緩嫻嬭瘯瀵硅薄錛屽嫻嬭瘯鐢ㄤ緥榪涜鑷姩鍖栫鐞嗐?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">6. 嫻嬭瘯鎵ц浣擄紙TestRunner錛夛細鐢ㄤ簬榪愯涓涓祴璇曘?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">浠ヤ笂鍚勬ā鍧楃殑涓昏綾葷戶鎵跨粨鏋勫涓嬶細</p><pre style="word-wrap: break-word; white-space: normal; line-height: 26px; text-align: left; background-color: #f5f5f5; color: green; ">Test TestFixture TestResult TestListener _______|_________ | | | | | TestSuccessListener TestComposite TestLeaf | | | |____________| TestResultCollector TestSuit | TestCase | TestCaller<Fixture> Outputter TestFactory TestRunner ____________________|_________________ | | | | TestFactoryRegistry CompilerOutputter TextOutputter XmlOutputter | TestSuiteFactory<TestCaseType></pre><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鎺ヤ笅鏉ュ啀瀵瑰叾涓竴浜涘叧閿被浣滀互浠嬬粛銆?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">Test錛氭墍鏈夋祴璇曞璞$殑鍩虹被銆?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">CppUnit閲囩敤鏍戝艦緇撴瀯鏉ョ粍緇囩鐞嗘祴璇曞璞★紙綾諱技浜庣洰褰曟爲錛夛紝鍥犳榪欓噷閲囩敤浜嗙粍鍚堣璁℃ā寮忥紙Composite Pattern錛夛紝Test鐨勪袱涓洿鎺ュ瓙綾籘estLeaf鍜孴estComposite鍒嗗埆琛ㄧず“嫻嬭瘯鏍?#8221;涓殑鍙惰妭鐐瑰拰闈炲彾鑺傜偣錛屽叾涓璗estComposite涓昏璧風粍緇囩鐞嗙殑浣滅敤錛屽氨鍍忕洰褰曟爲涓殑鏂囦歡澶癸紝鑰孴estLeaf鎵嶆槸鏈緇堝叿鏈夋墽琛岃兘鍔涚殑嫻嬭瘯瀵硅薄錛屽氨鍍忕洰褰曟爲涓殑鏂囦歡銆?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">Test鏈閲嶈鐨勪竴涓叕鍏辨帴鍙d負錛?/p><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">virtual void run(TestResult *result) = 0;</div><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鍏朵綔鐢ㄤ負鎵ц嫻嬭瘯瀵硅薄錛屽皢緇撴灉鎻愪氦緇檙esult銆?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鍦ㄥ疄闄呭簲鐢ㄤ腑錛屾垜浠竴鑸笉浼氱洿鎺ヤ嬌鐢═est銆乀estComposite浠ュ強TestLeaf錛岄櫎闈炴垜浠閲嶆柊瀹氬埗鏌愪簺鏈哄埗銆?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestFixture錛氱敤浜庣淮鎶や竴緇勬祴璇曠敤渚嬬殑涓婁笅鏂囩幆澧冦?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鍦ㄥ疄闄呭簲鐢ㄤ腑錛屾垜浠粡甯鎬細寮鍙戜竴緇勬祴璇曠敤渚嬫潵瀵規煇涓被鐨勬帴鍙e姞浠ユ祴璇曪紝鑰岃繖浜涙祴璇曠敤渚嬪緢鍙兘鍏鋒湁鐩稿悓鐨勫垵濮嬪寲鍜屾竻鐞嗕唬鐮併備負姝わ紝CppUnit寮曞叆TestFixture鏉ュ疄鐜拌繖涓鏈哄埗銆?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestFixture鍏鋒湁浠ヤ笅涓や釜鎺ュ彛錛屽垎鍒敤浜庡鐞嗘祴璇曠幆澧冪殑鍒濆鍖栦笌娓呯悊宸ヤ綔錛?/p><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">virtual void setUp(); <br />virtual void tearDown(); </div><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestCase錛氭祴璇曠敤渚嬶紝浠庡悕瀛椾笂灝卞彲浠ョ湅鍑烘潵錛屽畠渚挎槸鍗曞厓嫻嬭瘯鐨勬墽琛屽璞°?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestCase浠嶵est鍜孴estFixture澶氱戶鎵胯屾潵錛岄氳繃鎶奣est::run鍒跺畾鎴愭ā鏉垮嚱鏁幫紙Template Method錛夎屽皢涓や釜鐖剁被鐨勬搷浣滆瀺鍚堝湪涓璧鳳紝run鍑芥暟鐨勪吉瀹氫箟濡備笅錛?/p><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">// 浼唬鐮?nbsp;<br />void TestCase::run(TestResult* result)<br />{<br />    result->startTest(this); // 閫氱煡result嫻嬭瘯寮濮?br />    if( result->protect(this, &TestCase::setUp) ) // 璋冪敤setUp錛屽垵濮嬪寲鐜<br />        result->protect(this, &TestCase::runTest); // 鎵цrunTest錛屽嵆鐪熸鐨勬祴璇曚唬鐮?br />    result->protect(this, &TestCase::tearDown); // 璋冪敤tearDown錛屾竻鐞嗙幆澧?br />    result->endTest(this); // 閫氱煡result嫻嬭瘯緇撴潫<br />}</div><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">榪欓噷瑕佹彁鍒扮殑鏄嚱鏁皉unTest錛屽畠鏄疶estCase瀹氫箟鐨勪竴涓帴鍙o紝鍘熷瀷濡備笅錛?/p><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">virtual void runTest();</div><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鐢ㄦ埛闇浠嶵estCase媧劇敓鍑哄瓙綾誨茍瀹炵幇runTest浠ュ紑鍙戣嚜宸辨墍闇鐨勬祴璇曠敤渚嬨?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鍙﹀榪樿鎻愬埌鐨勫氨鏄疶estResult鐨刾rotect鏂規硶錛屽叾浣滅敤鏄鎵ц鍑芥暟錛堝疄闄呬笂鏄嚱鏁板璞★級鐨勯敊璇俊鎭紙鍖呮嫭鏂█鍜屽紓甯哥瓑錛夎繘琛屾崟鑾鳳紝浠庤屽疄鐜板嫻嬭瘯緇撴灉鐨勭粺璁°?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestSuit錛氭祴璇曞寘錛屾寜鐓ф爲褰㈢粨鏋勭鐞嗘祴璇曠敤渚?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestSuit鏄疶estComposite鐨勪竴涓疄鐜幫紝瀹冮噰鐢╲ector鏉ョ鐞嗗瓙嫻嬭瘯瀵硅薄錛圱est錛夛紝浠庤屽艦鎴愰掑綊鐨勬爲褰㈢粨鏋勩?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestCaller錛歍estCase閫傞厤鍣紙Adapter錛夛紝瀹冨皢鎴愬憳鍑芥暟杞崲鎴愭祴璇曠敤渚?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">铏界劧鎴戜滑鍙互浠嶵estCase媧劇敓鑷繁鐨勬祴璇曠被錛屼絾浠嶵estCase綾葷殑瀹氫箟鍙互鐪嬪嚭錛屽畠鍙兘鏀寔涓涓祴璇曠敤渚嬶紝榪欏浜庢祴璇曚唬鐮佺殑緇勭粐鍜岀淮鎶ゅ緢涓嶆柟渚匡紝灝ゅ叾鏄偅浜涙湁鍏卞悓涓婁笅鏂囩幆澧冪殑涓緇勬祴璇曘備負姝わ紝CppUnit鎻愪緵浜員estCaller浠ヨВ鍐寵繖涓棶棰樸?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestCaller鏄竴涓ā鏉跨被錛屽畠浠ュ疄鐜頒簡TestFixture鎺ュ彛鐨勭被涓烘ā鏉垮弬鏁幫紝灝嗙洰鏍囩被涓煇涓鍚坮unTest鍘熷瀷鐨勬祴璇曟柟娉曢傞厤鎴怲estCase鐨勫瓙綾匯?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鍦ㄥ疄闄呭簲鐢ㄤ腑錛屾垜浠ぇ澶氶噰鐢═estFixture鍜孴estCaller鐩哥粍鍚堢殑鏂瑰紡錛屽叿浣撲緥瀛愬弬瑙佸悗鏂囥?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestResult鍜孴estListener錛氬鐞嗘祴璇曚俊鎭拰緇撴灉</p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鍓嶉潰宸茬粡鎻愬埌錛孴estResult鍜孴estListener閲囩敤浜嗚瀵熻呮ā寮忥紝TestResult緇存姢涓涓敞鍐岃〃錛岀敤浜庣鐞嗗悜鍏剁櫥璁拌繃鐨凾estListener錛屽綋TestResult鏀跺埌嫻嬭瘯瀵硅薄錛圱est錛夌殑嫻嬭瘯淇℃伅鏃訛紝鍐嶄竴涓鍒嗗彂緇欏畠鎵綆¤緰鐨凾estListener銆傝繖涓璁捐鏈夊姪浜庡疄鐜板鍚屼竴嫻嬭瘯鐨勫縐嶅鐞嗘柟寮忋?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestFactory錛氭祴璇曞伐鍘?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">榪欐槸涓涓緟鍔╃被錛岄氳繃鍊熷姪涓緋誨垪瀹忓畾涔夎嫻嬭瘯鐢ㄤ緥鐨勭粍緇囩鐞嗗彉寰楄嚜鍔ㄥ寲銆傚弬瑙佸悗闈㈢殑渚嬪瓙銆?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestRunner錛氱敤浜庢墽琛屾祴璇曠敤渚?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestRunner灝嗗緟鎵ц鐨勬祴璇曞璞$鐞嗚搗鏉ワ紝鐒跺悗渚涚敤鎴瘋皟鐢ㄣ傚叾鎺ュ彛涓猴細</p><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">virtual void addTest( Test *test ); virtual void run( TestResult &controller, const std::string &testPath = "" );</div><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">榪欎篃鏄竴涓緟鍔╃被錛岄渶娉ㄦ剰鐨勬槸錛岄氳繃addTest娣誨姞鍒癟estRunner涓殑嫻嬭瘯瀵硅薄蹇呴』鏄氳繃new鍔ㄦ佸垱寤虹殑錛岀敤鎴蜂笉鑳藉垹闄よ繖涓璞★紝鍥犱負TestRunner灝嗚嚜琛岀鐞嗘祴璇曞璞$殑鐢熷懡鏈熴?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">浣跨敤</p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鍏堣鎴戜滑鐪嬬湅涓涓畝鍗曠殑渚嬪瓙錛?/p><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">#include <cppunit/TestCase.h><br />#include <cppunit/TestResult.h><br />#include <cppunit/TestResultCollector.h><br />#include <cppunit/TextOutputter.h><br /><br />// 瀹氫箟嫻嬭瘯鐢ㄤ緥<br />class SimpleTest : public CppUnit::TestCase<br />{<br />public:<br />    void runTest() // 閲嶈澆嫻嬭瘯鏂規硶<br />    {<br />        int i = 1;<br />        CPPUNIT_ASSERT_EQUAL(0, i);<br />    }<br />};<br /><br />int main(int argc, char* argv[])<br />{<br />    CppUnit::TestResult r; <br />    CppUnit::TestResultCollector rc;<br />    r.addListener(&rc); // 鍑嗗濂界粨鏋滄敹闆嗗櫒 <br /><br />    SimpleTest t;<br />    t.run(&r); // 榪愯嫻嬭瘯鐢ㄤ緥<br /><br />    CppUnit::TextOutputter o(&rc, std::cout);<br />    o.write(); // 灝嗙粨鏋滆緭鍑?br /><br />    return 0;<br />}</div><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">緙栬瘧鍚庤繍琛岋紝杈撳嚭緇撴灉涓猴細</span><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">!!!FAILURES!!!<br />Test Results:<br />Run: 1 Failures: 1 Errors: 0<br /><br />1) test: (F) line: 18 E:/CppUnitExamples/SimpleTest.cpp<br />equality assertion failed<br />- Expected: 1<br />- Actual : 0</div><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">涓婇潰鐨勪緥瀛愬緢綆鍗曪紝闇璇存槑鐨勬槸CPPUNIT_ASSERT_EQUAL瀹忋侰ppUnit瀹氫箟浜嗕竴緇勫畯鐢ㄤ簬媯嫻嬮敊璇紝CPPUNIT_ASSERT_EQUAL鏄叾涓箣涓錛屽綋鏂█澶辮觸鏃訛紝CppUnit渚夸細灝嗛敊璇俊鎭姤鍛婄粰TestResult銆傝繖浜涘畯瀹氫箟鐨勮鏄庡涓嬶細</p><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><p>CPPUNIT_ASSERT(condition)錛氬垽鏂璫ondition鐨勫兼槸鍚︿負鐪燂紝濡傛灉涓哄亣鍒欑敓鎴愰敊璇俊鎭?/p><p>CPPUNIT_ASSERT_MESSAGE(message, condition)錛氫笌CPPUNIT_ASSERT綾諱技錛屼絾緇撴灉涓哄亣鏃舵姤鍛妋esssage淇℃伅銆?/p><p>CPPUNIT_FAIL(message)錛氱洿鎺ユ姤鍛妋esssage閿欒淇℃伅銆?/p><p>CPPUNIT_ASSERT_EQUAL(expected, actual)錛氬垽鏂璭xpected鍜宎ctual鐨勫兼槸鍚︾浉絳夛紝濡傛灉涓嶇瓑杈撳嚭閿欒淇℃伅銆?/p><p>CPPUNIT_ASSERT_EQUAL_MESSAGE(message, expected, actual)錛氫笌CPPUNIT_ASSERT_EQUAL綾諱技錛屼絾鏂█澶辮觸鏃惰緭鍑簃essage淇℃伅銆?/p><p>CPPUNIT_ASSERT_DOUBLES_EQUAL(expected, actual, delta)錛氬垽鏂璭xpected涓巃ctual鐨勫亸宸槸鍚﹀皬浜巇elta錛岀敤浜庢誕鐐規暟姣旇緝銆?/p><p>CPPUNIT_ASSERT_THROW(expression, ExceptionType)錛氬垽鏂墽琛岃〃杈懼紡expression鍚庢槸鍚︽姏鍑篍xceptionType寮傚父銆?/p><p>CPPUNIT_ASSERT_NO_THROW(expression)錛氭柇璦鎵ц琛ㄨ揪寮廵xpression鍚庢棤寮傚父鎶涘嚭銆?/p></div><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鎺ヤ笅鏉ュ啀鐪嬬湅TestFixture鍜孴estCaller鐨勭粍鍚堜嬌鐢細</p><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">#include <cppunit/TestCase.h><br />#include <cppunit/TestResult.h><br />#include <cppunit/TestResultCollector.h><br />#include <cppunit/TextOutputter.h><br />#include <cppunit/TestCaller.h><br />#include <cppunit/TestRunner.h><br /><br />// 瀹氫箟嫻嬭瘯綾?br />class StringTest : public CppUnit::TestFixture<br />{<br />public:<br />    void setUp() // 鍒濆鍖?br />    {<br />        m_str1 = "Hello, world";<br />        m_str2 = "Hi, cppunit";<br />    }<br /><br />    void tearDown() // 娓呯悊<br />    {<br />    }<br /><br />    void testSwap() // 嫻嬭瘯鏂規硶1<br />    {<br />        std::string str1 = m_str1;<br />        std::string str2 = m_str2;<br />        m_str1.swap(m_str2);<br />        <br />        CPPUNIT_ASSERT(m_str1 == str2);<br />        CPPUNIT_ASSERT(m_str2 == str1);<br />    }<br /><br />    void testFind() // 嫻嬭瘯鏂規硶2<br />    {<br />        int pos1 = m_str1.find(',');<br />        int pos2 = m_str2.rfind(',');<br /><br />        CPPUNIT_ASSERT_EQUAL(5, pos1);<br />        CPPUNIT_ASSERT_EQUAL(2, pos2);<br />    }<br /><br />protected:<br />    std::string     m_str1;<br />    std::string     m_str2;<br />};<br /><br />int main(int argc, char* argv[])<br />{<br />    CppUnit::TestResult r; <br />    CppUnit::TestResultCollector rc;<br />    r.addListener(&rc); // 鍑嗗濂界粨鏋滄敹闆嗗櫒 <br /><br />    CppUnit::TestRunner runner; // 瀹氫箟鎵ц瀹炰綋<br />    runner.addTest(new CppUnit::TestCaller<StringTest>("testSwap", &StringTest::testSwap)); // 鏋勫緩嫻嬭瘯鐢ㄤ緥1<br />    runner.addTest(new CppUnit::TestCaller<StringTest>("testFind", &StringTest::testFind)); // 鏋勫緩嫻嬭瘯鐢ㄤ緥2<br />    runner.run(r); // 榪愯嫻嬭瘯<br /><br />    CppUnit::TextOutputter o(&rc, std::cout);<br />    o.write(); // 灝嗙粨鏋滆緭鍑?br /><br />    return rc.wasSuccessful() ? 0 : -1;<br />}</div><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">緙栬瘧鍚庤繍琛岀粨鏋滀負錛?/span><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">OK (2 tests)</div><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">涓婇潰鐨勪唬鐮佷粠鍔熻兘涓婅娌℃湁浠涔堥棶棰橈紝浣嗙紪鍐欒搗鏉ュお綣佺悙浜嗭紝涓烘錛屾垜浠彲浠ュ熷姪CppUnit瀹氫箟鐨勪竴濂楄緟鍔╁畯錛屽皢嫻嬭瘯鐢ㄤ緥鐨勫畾涔夊拰娉ㄥ唽鍙樺緱鑷姩鍖栥備笂闈㈢殑浠g爜鏀歸犲悗濡備笅錛?/p><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">#include <cppunit/TestResult.h><br />#include <cppunit/TestResultCollector.h><br />#include <cppunit/TextOutputter.h><br />#include <cppunit/TestRunner.h><br />#include <cppunit/extensions/HelperMacros.h><br /><br /><br />// 瀹氫箟嫻嬭瘯綾?br />class StringTest : public CppUnit::TestFixture<br />{<br />    CPPUNIT_TEST_SUITE(StringTest);  // 瀹氫箟嫻嬭瘯鍖?br />    CPPUNIT_TEST(testSwap);  // 娣誨姞嫻嬭瘯鐢ㄤ緥1<br />    CPPUNIT_TEST(testFind);  // 娣誨姞嫻嬭瘯鐢ㄤ緥2<br />    CPPUNIT_TEST_SUITE_END();  // 緇撴潫嫻嬭瘯鍖呭畾涔?br />    <br />public:<br />    void setUp() // 鍒濆鍖?br />    {<br />        m_str1 = "Hello, world";<br />        m_str2 = "Hi, cppunit";<br />    }<br /><br />    void tearDown() // 娓呯悊<br />    {<br />    }<br /><br />    void testSwap() // 嫻嬭瘯鏂規硶1<br />    {<br />        std::string str1 = m_str1;<br />        std::string str2 = m_str2;<br />        m_str1.swap(m_str2);<br />        <br />        CPPUNIT_ASSERT(m_str1 == str2);<br />        CPPUNIT_ASSERT(m_str2 == str1);<br />    }<br /><br />    void testFind() // 嫻嬭瘯鏂規硶2<br />    {<br />        int pos1 = m_str1.find(',');<br />        int pos2 = m_str2.rfind(',');<br /><br />        CPPUNIT_ASSERT_EQUAL(5, pos1);<br />        CPPUNIT_ASSERT_EQUAL(2, pos2);<br />    }<br /><br />protected:<br />    std::string     m_str1;<br />    std::string     m_str2;<br />};<br /><br />CPPUNIT_TEST_SUITE_REGISTRATION(StringTest); // 鑷姩娉ㄥ唽嫻嬭瘯鍖?br /><br />int main(int argc, char* argv[])<br />{<br />    CppUnit::TestResult r; <br />    CppUnit::TestResultCollector rc;<br />    r.addListener(&rc); // 鍑嗗濂界粨鏋滄敹闆嗗櫒 <br /><br />    CppUnit::TestRunner runner; // 瀹氫箟鎵ц瀹炰綋<br />    runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());<br />    runner.run(r); // 榪愯嫻嬭瘯<br /><br />    CppUnit::TextOutputter o(&rc, std::cout);<br />    o.write(); // 灝嗙粨鏋滆緭鍑?br /><br />    return rc.wasSuccessful() ? 0 : -1;<br />}</div><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">CppUnit鐨勭畝鍗曚粙緇嶅氨鍒版錛岀浉淇′綘宸茬粡浜嗚В浜嗗叾涓殑鍩烘湰姒傚康錛屼篃鑳藉寮鍙戝崟鍏冩祴璇曚唬鐮佷簡銆?br /><br />杞嚜錛?a >http://blog.csdn.net/freefalcon/article/details/753819</a></p><img src ="http://www.shnenglu.com/tankzhouqiang/aggbug/166911.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/tankzhouqiang/" target="_blank">鍛ㄥ己</a> 2012-03-01 20:25 <a href="http://www.shnenglu.com/tankzhouqiang/archive/2012/03/01/166911.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鍒嗗竷寮?/title><link>http://www.shnenglu.com/tankzhouqiang/archive/2011/12/25/162809.html</link><dc:creator>鍛ㄥ己</dc:creator><author>鍛ㄥ己</author><pubDate>Sun, 25 Dec 2011 15:49:00 GMT</pubDate><guid>http://www.shnenglu.com/tankzhouqiang/archive/2011/12/25/162809.html</guid><wfw:comment>http://www.shnenglu.com/tankzhouqiang/comments/162809.html</wfw:comment><comments>http://www.shnenglu.com/tankzhouqiang/archive/2011/12/25/162809.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/tankzhouqiang/comments/commentRss/162809.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/tankzhouqiang/services/trackbacks/162809.html</trackback:ping><description><![CDATA[<div>     鍙戠幇宸茬粡寰堜箙娌″啓鍗氬浜嗭紝涓昏鍓嶆鏃墮棿瀹炲湪澶繖浜嗭紝瀹炰範錛屾壘宸ヤ綔錛屾瘯涓氱瓟杈╋紝緇忓巻浜嗗緢澶氫簨鎯咃紝鐜板湪緇堜簬絀洪棽涓嬫潵浜嗐備粠鏄庡ぉ寮濮嬭鐮旂┒涓嬪垎甯冨紡緋葷粺浜嗭紝璁″垝璁捐瀹炵幇涓垎甯冨紡鏁版嵁搴撱?/div><img src ="http://www.shnenglu.com/tankzhouqiang/aggbug/162809.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/tankzhouqiang/" target="_blank">鍛ㄥ己</a> 2011-12-25 23:49 <a href="http://www.shnenglu.com/tankzhouqiang/archive/2011/12/25/162809.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>姹熸箹http://www.shnenglu.com/tankzhouqiang/archive/2011/08/13/153315.html鍛ㄥ己鍛ㄥ己Sat, 13 Aug 2011 15:45:00 GMThttp://www.shnenglu.com/tankzhouqiang/archive/2011/08/13/153315.htmlhttp://www.shnenglu.com/tankzhouqiang/comments/153315.htmlhttp://www.shnenglu.com/tankzhouqiang/archive/2011/08/13/153315.html#Feedback5http://www.shnenglu.com/tankzhouqiang/comments/commentRss/153315.htmlhttp://www.shnenglu.com/tankzhouqiang/services/trackbacks/153315.html   

鍛ㄥ己 2011-08-13 23:45 鍙戣〃璇勮
]]>
亚洲国产高清精品线久久| 伊色综合久久之综合久久| 精产国品久久一二三产区区别 | 久久久久国产精品三级网| 国产91久久精品一区二区| jizzjizz国产精品久久| 国产精品久久久久影院嫩草| 久久免费视频观看| 国产午夜精品久久久久九九电影 | 久久精品二区| 午夜精品久久影院蜜桃| 久久只这里是精品66| 亚洲国产精品18久久久久久| 99久久久国产精品免费无卡顿 | 91精品国产色综久久| 久久99精品久久久久久不卡| 久久精品综合一区二区三区| 99久久免费国产精品特黄| 久久久久久久久久久久久久| 久久久久久人妻无码| 久久精品国产99国产精偷| 久久久久亚洲?V成人无码| 香港aa三级久久三级老师2021国产三级精品三级在 | 久久夜色撩人精品国产| 亚洲欧美精品一区久久中文字幕 | 久久精品综合网| 国产精品无码久久综合 | 欧美亚洲国产精品久久| 久久久久久久人妻无码中文字幕爆 | 欧美日韩久久中文字幕| 国产精品美女久久久久网| 四虎影视久久久免费| 人妻精品久久无码区| 国产免费福利体检区久久| 精品久久亚洲中文无码| 国产伊人久久| 久久精品国产网红主播| 午夜精品久久久久久| 欧美777精品久久久久网| 色综合久久久久无码专区| 久久久网中文字幕|