使用并发参数编译项目和运行单元测试


一、MSBuild并发编译

平常使用Jenkins构建项目时,默认使用MSbuild中没有带并发参数,所以比较慢

不带并发参数构建为

msbuild 项目路径

带并发参数, 只要有这个开关默认使用最大的并发数,当然你也可以指定CPU的数量

msbuild 项目路径 -maxCpuCount

当然这里只是简写,还有很多参数需要你根据自己具体项目添加

写一个bat批处理计算编译花费时间

@echo off
setlocal

rem The format of %TIME% is HH:MM:SS,CS for example 23:59:59,99
set STARTTIME=%TIME%

rem here begins the command you want to measure

:: ======================  msbuild命令行  ===================

rem here ends the command you want to measu
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 以下是使用 C 语言实现密码卡使用 SM4 对称加密的示例代码: ```c #include <stdio.h> #include <string.h> #define BLOCK_SIZE 16 void sm4_encrypt(unsigned char *key, unsigned char *plaintext, unsigned char *ciphertext); void sm4_decrypt(unsigned char *key, unsigned char *ciphertext, unsigned char *plaintext); int main() { // 密钥 unsigned char key[16] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10}; // 明文 unsigned char plaintext[] = "This is a test message."; // 密文缓冲区 unsigned char ciphertext[sizeof(plaintext)]; // 并发会话部分 // 执行加密操作 sm4_encrypt(key, plaintext, ciphertext); printf("Ciphertext: %s\n", ciphertext); // 执行解密操作 sm4_decrypt(key, ciphertext, plaintext); printf("Plaintext: %s\n", plaintext); return 0; } // SM4 加密函数 void sm4_encrypt(unsigned char *key, unsigned char *plaintext, unsigned char *ciphertext) { // 省略具体实现 } // SM4 解密函数 void sm4_decrypt(unsigned char *key, unsigned char *ciphertext, unsigned char *plaintext) { // 省略具体实现 } ``` 上面是一个简单的示例代码,实际项目中你可能需要在 sm4_encrypt 和 sm4_decrypt 函数中实现 SM4 加密和解密的具体操作,这里省略了具体实现。 这段代码实现了密码卡使用SM4对称加密的并发会话测试, 其中并发会话部分包含了执行加密操作和执行解密操作,main函数中的代码需要 ### 回答2: 要实现密码卡使用SM4对称加密的并发会话测试,可以使用C代码进行编写。首先,需要引入相应的库和头文件。 ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <pthread.h> #include "sm4.h" #define MAX_THREADS 10 // 最大线程数 #define MESSAGE_SIZE 16 // 消息长度 pthread_mutex_t mutex; // 互斥锁 // 加密函数 void encryptMessage(unsigned char *message, unsigned char *key) { unsigned char iv[16] = {0}; // 初始化向量,可以随机生成或者约定固定值 sm4_context ctx; sm4_setkey_enc(&ctx, key); sm4_crypt_cbc(&ctx, SM4_ENCRYPT, MESSAGE_SIZE, iv, message, message); } // 解密函数 void decryptMessage(unsigned char *message, unsigned char *key) { unsigned char iv[16] = {0}; // 初始化向量,与加密时一致 sm4_context ctx; sm4_setkey_dec(&ctx, key); sm4_crypt_cbc(&ctx, SM4_DECRYPT, MESSAGE_SIZE, iv, message, message); } // 线程函数 void* concurrentSession(void *arg) { unsigned char *key = (unsigned char *)arg; // 获取传入的密钥 unsigned char message[MESSAGE_SIZE] = "Hello, World!"; // 需要加密的消息 // 加密消息 encryptMessage(message, key); // 打印加密后的结果 pthread_mutex_lock(&mutex); printf("Thread ID: %lu, Encrypted Message: ", pthread_self()); for (int i = 0; i < MESSAGE_SIZE; i++) { printf("%02x ", message[i]); } printf("\n"); pthread_mutex_unlock(&mutex); // 解密消息 decryptMessage(message, key); // 打印解密后的结果 pthread_mutex_lock(&mutex); printf("Thread ID: %lu, Decrypted Message: %s\n", pthread_self(), message); pthread_mutex_unlock(&mutex); pthread_exit(NULL); } int main() { pthread_t threads[MAX_THREADS]; // 线程数组 unsigned char key[16] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}; // 密钥 pthread_mutex_init(&mutex, NULL); // 初始化互斥锁 // 创建多个线程进行并发会话 for (int i = 0; i < MAX_THREADS; i++) { pthread_create(&threads[i], NULL, concurrentSession, key); } // 等待所有线程结束 for (int i = 0; i < MAX_THREADS; i++) { pthread_join(threads[i], NULL); } pthread_mutex_destroy(&mutex); // 销毁互斥锁 return 0; } ``` 以上是一个简单的C代码实现,用于并发会话测试。程序中使用了SM4对称加密算法对消息进行加密和解密。首先,定义了加密函数`encryptMessage`和解密函数`decryptMessage`,利用SM4算法进行加密和解密。然后,定义了线程函数`concurrentSession`,该函数接收密钥作为参数,并在每个线程中进行加密和解密操作。在主函数中,通过创建多个线程进行并发会话测试。每个线程都会获得相同的密钥,并对消息进行加密和解密。最后,使用互斥锁确保线程安全地打印结果。 ### 回答3: 要使用C代码实现密码卡的SM4对称加密的并发会话测试,可以按照以下步骤进行: 首先,需要定义SM4加密算法所需的密钥和明文数据。可以使用C语言的数组来存储这些数据。 接下来,需要编写一个函数来实现SM4加密算法。可以使用现有的密码库或自己实现SM4算法,在函数中传入密钥和明文数据,并输出加密结果。 然后,需要编写一个函数来模拟并发会话。可以使用C语言的线程库创建多个线程,并在每个线程中调用SM4加密函数进行加密操作。可以使用互斥锁来保护共享资源,例如加密结果的输出。 在主函数中,可以定义需要的线程数量,并创建相应数量的线程。然后,可以等待所有线程执行完毕,输出加密结果。 最后,可以编译运行这段代码,观察并发会话的效果。可以通过比较加密结果来验证并发会话的正确性。 需要注意的是,并发会话可能涉及到线程间的竞争条件和资源共享问题,需要使用互斥锁或其他并发控制手段来保证正确性和安全性。同时,密码卡的使用也需要遵循相关的安全规范和注意事项,以保障数据的安全性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值