PageRenderTime 21ms CodeModel.GetById 10ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/tests/llallocator_heap_profile_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 144 lines | 97 code | 16 blank | 31 comment | 0 complexity | a0da9c611c545e2e6d0b107a417a7e3d MD5 | raw file
  1/**
  2 * @file   llallocator_heap_profile_test.cpp
  3 * @author Brad Kittenbrink
  4 * @date   2008-02-
  5 * @brief  Test for llallocator_heap_profile.cpp.
  6 * 
  7 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2010, Linden Research, Inc.
 10 * 
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 * 
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 * 
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 * 
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28
 29#include "../llallocator_heap_profile.h"
 30#include "../test/lltut.h"
 31
 32namespace tut
 33{
 34    struct llallocator_heap_profile_data
 35    {
 36        LLAllocatorHeapProfile prof;
 37
 38        static char const * const sample_win_profile;
 39        // *TODO - get test output from mac/linux tcmalloc
 40        static char const * const sample_mac_profile;
 41        static char const * const sample_lin_profile;
 42
 43        static char const * const crash_testcase;
 44    };
 45    typedef test_group<llallocator_heap_profile_data> factory;
 46    typedef factory::object object;
 47}
 48namespace
 49{
 50        tut::factory llallocator_heap_profile_test_factory("LLAllocatorHeapProfile");
 51}
 52
 53namespace tut
 54{
 55    template<> template<>
 56    void object::test<1>()
 57    {
 58        prof.parse(sample_win_profile);
 59
 60        ensure_equals("count lines", prof.mLines.size() , 5);
 61        ensure_equals("alloc counts", prof.mLines[0].mLiveCount, 2131854U);
 62        ensure_equals("alloc counts", prof.mLines[0].mLiveSize, 2245710106ULL);
 63        ensure_equals("alloc counts", prof.mLines[0].mTotalCount, 14069198U);
 64        ensure_equals("alloc counts", prof.mLines[0].mTotalSize, 4295177308ULL);
 65        ensure_equals("count markers", prof.mLines[0].mTrace.size(), 0);
 66        ensure_equals("count markers", prof.mLines[1].mTrace.size(), 0);
 67        ensure_equals("count markers", prof.mLines[2].mTrace.size(), 4);
 68        ensure_equals("count markers", prof.mLines[3].mTrace.size(), 6);
 69        ensure_equals("count markers", prof.mLines[4].mTrace.size(), 7);
 70
 71        //prof.dump(std::cout);
 72    }
 73
 74    template<> template<>
 75    void object::test<2>()
 76    {
 77        prof.parse(crash_testcase);
 78
 79        ensure_equals("count lines", prof.mLines.size(), 2);
 80        ensure_equals("alloc counts", prof.mLines[0].mLiveCount, 3U);
 81        ensure_equals("alloc counts", prof.mLines[0].mLiveSize, 1049652ULL);
 82        ensure_equals("alloc counts", prof.mLines[0].mTotalCount, 8U);
 83        ensure_equals("alloc counts", prof.mLines[0].mTotalSize, 1049748ULL);
 84        ensure_equals("count markers", prof.mLines[0].mTrace.size(), 0);
 85        ensure_equals("count markers", prof.mLines[1].mTrace.size(), 0);
 86
 87        //prof.dump(std::cout);
 88    }
 89
 90    template<> template<>
 91    void object::test<3>()
 92    {
 93        // test that we don't crash on edge case data
 94        prof.parse("");
 95        ensure("emtpy on error", prof.mLines.empty());
 96
 97        prof.parse("heap profile:");
 98        ensure("emtpy on error", prof.mLines.empty());
 99    }
100
101char const * const llallocator_heap_profile_data::sample_win_profile =
102"heap profile: 2131854: 2245710106 [14069198: 4295177308] @\n"
103"308592: 1073398388 [966564: 1280998739] @\n"
104"462651: 375969538 [1177377: 753561247] @        2        3        6        1\n"
105"314744: 206611283 [2008722: 570934755] @        2        3        3        7       21       32\n"
106"277152: 82862770 [621961: 168503640] @        2        3        3        7       21       32       87\n"
107"\n"
108"MAPPED_LIBRARIES:\n"
109"00400000-02681000 r-xp 00000000 00:00 0           c:\\proj\\tcmalloc-eval-9\\indra\\build-vc80\\newview\\RelWithDebInfo\\secondlife-bin.exe\n"
110"77280000-773a7000 r-xp 00000000 00:00 0           C:\\Windows\\system32\\ntdll.dll\n"
111"76df0000-76ecb000 r-xp 00000000 00:00 0           C:\\Windows\\system32\\kernel32.dll\n"
112"76000000-76073000 r-xp 00000000 00:00 0           C:\\Windows\\system32\\comdlg32.dll\n"
113"75ee0000-75f8a000 r-xp 00000000 00:00 0           C:\\Windows\\system32\\msvcrt.dll\n"
114"76c30000-76c88000 r-xp 00000000 00:00 0           C:\\Windows\\system32\\SHLWAPI.dll\n"
115"75f90000-75fdb000 r-xp 00000000 00:00 0           C:\\Windows\\system32\\GDI32.dll\n"
116"77420000-774bd000 r-xp 00000000 00:00 0           C:\\Windows\\system32\\USER32.dll\n"
117"75e10000-75ed6000 r-xp 00000000 00:00 0           C:\\Windows\\system32\\ADVAPI32.dll\n"
118"75b00000-75bc2000 r-xp 00000000 00:00 0           C:\\Windows\\system32\\RPCRT4.dll\n"
119"72ca0000-72d25000 r-xp 00000000 00:00 0           C:\\Windows\\WinSxS\\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.6001.18000_none_886786f450a74a05\\COMCTL32.dll\n"
120"76120000-76c30000 r-xp 00000000 00:00 0           C:\\Windows\\system32\\SHELL32.dll\n"
121"71ce0000-71d13000 r-xp 00000000 00:00 0           C:\\Windows\\system32\\DINPUT8.dll\n";
122
123
124char const * const llallocator_heap_profile_data::crash_testcase =
125"heap profile:      3:  1049652 [     8:  1049748] @\n"
126"     3:  1049652 [     8:  1049748] @\n"
127"\n"
128"MAPPED_LIBRARIES:\n"
129"00400000-004d5000 r-xp 00000000 00:00 0           c:\\code\\linden\\tcmalloc\\indra\\build-vc80\\llcommon\\RelWithDebInfo\\llallocator_test.exe\n"
130"7c900000-7c9af000 r-xp 00000000 00:00 0           C:\\WINDOWS\\system32\\ntdll.dll\n"
131"7c800000-7c8f6000 r-xp 00000000 00:00 0           C:\\WINDOWS\\system32\\kernel32.dll\n"
132"77dd0000-77e6b000 r-xp 00000000 00:00 0           C:\\WINDOWS\\system32\\ADVAPI32.dll\n"
133"77e70000-77f02000 r-xp 00000000 00:00 0           C:\\WINDOWS\\system32\\RPCRT4.dll\n"
134"77fe0000-77ff1000 r-xp 00000000 00:00 0           C:\\WINDOWS\\system32\\Secur32.dll\n"
135"71ab0000-71ac7000 r-xp 00000000 00:00 0           C:\\WINDOWS\\system32\\WS2_32.dll\n"
136"77c10000-77c68000 r-xp 00000000 00:00 0           C:\\WINDOWS\\system32\\msvcrt.dll\n"
137"71aa0000-71aa8000 r-xp 00000000 00:00 0           C:\\WINDOWS\\system32\\WS2HELP.dll\n"
138"76bf0000-76bfb000 r-xp 00000000 00:00 0           C:\\WINDOWS\\system32\\PSAPI.DLL\n"
139"5b860000-5b8b5000 r-xp 00000000 00:00 0           C:\\WINDOWS\\system32\\NETAPI32.dll\n"
140"10000000-10041000 r-xp 00000000 00:00 0           c:\\code\\linden\\tcmalloc\\indra\\build-vc80\\llcommon\\RelWithDebInfo\\libtcmalloc_minimal.dll\n"
141"7c420000-7c4a7000 r-xp 00000000 00:00 0           C:\\WINDOWS\\WinSxS\\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.1433_x-ww_5cf844d2\\MSVCP80.dll\n"
142"78130000-781cb000 r-xp 00000000 00:00 0           C:\\WINDOWS\\WinSxS\\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.1433_x-ww_5cf844d2\\MSVCR80.dll\n";
143
144}