#! /usr/bin/env python3
# -*- coding: UTF-8 -*-
# ----------------------------------------------------------------------------------------------------------
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
# CANN Open Software License Agreement Version 2.0 (the "License").
# Please refer to the License for details. You may not use this file except in compliance with the License.
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
# See LICENSE in the root of the software repository for the full text of the License.
# ----------------------------------------------------------------------------------------------------------
import os
import sys
import shutil
import unittest
import subprocess
import filecmp

from unittest.mock import MagicMock, patch

THIS_FILE_NAME = __file__
FILE_PATH = os.path.dirname(os.path.realpath(THIS_FILE_NAME))
MSOBJDUMP_PATH = os.path.join(FILE_PATH, "../../../", "tools/scripts/compile_trace_log/")
print(MSOBJDUMP_PATH)
sys.path.append(MSOBJDUMP_PATH)
from compile_trace_log import compile_trace

class TestCompileTrace(unittest.TestCase):
    def setUp(self):
        # 每个测试用例执行之前做操作
        print("---------------------set up case----------------------------------")

    def tearDown(self):
        # 每个测试用例执行之后做操作
        print("---------------------tear down case-------------------------------")

    def test_compile_trace(self):
        a = 0
        #有编译打点时间日志
        input_file = os.path.join(FILE_PATH, "valid.txt" )        # 修改为你实际的日志文件名
        output_file = os.path.join(FILE_PATH, "valid_trace_output.json" )   # 输出的 JSON 文件名
        compile_trace(input_file, output_file)
        if filecmp.cmp(output_file, FILE_PATH + '/valid_golden.json'):
            print("The contents of the two files are the same")
            a += 1
        else:
            print("The contents of the two files are different")

        if a == 1:
            print("[SUCCESS]")
        else:
            assert False, "[FAILED]"
        # clear datalog.txt generated by compile_trace()
        file_to_del = os.path.join(FILE_PATH, "../../../datalog.txt")
        if os.path.exists(file_to_del):
            os.remove(file_to_del)


if __name__ == "__main__":
    unittest.main()