개요
: Android OS 에서 monkey 를 사용 자동 touch 를 동작 하게 한다.


Script

// monkey.txt


type= user

speed= 1000

start data >>

DispatchPointer(0, 0, 0, 1155, 1158, 0,0,0,0,0,0,0) // touch

DispatchPointer(0, 0, 1, 1155, 1158, 0,0,0,0,0,0,0) // release

UserWait(32000) // wait for 32s

DispatchPointer(0, 0, 0, 42, 45, 0,0,0,0,0,0,0) // touch

DispatchPointer(0, 0, 1, 42, 45, 0,0,0,0,0,0,0) // release

UserWait(1000)

DispatchPointer(0, 0, 0, 2025, 36, 0,0,0,0,0,0,0) // touch

DispatchPointer(0, 0, 1, 2025, 36, 0,0,0,0,0,0,0) // release

quit 


PC 사용 command

 $adb push monkey.txt /data/log/monkey.txt      // monkey script 를 phone 에 밀어 넣기

 $adb shell monkey -f /data/log/monkey.txt 1     // monkey 실행 마지막 숫자는 반복 횟수 


monkey 멈추기

 $adb shell

 $ps | grep monkey

 $kill <process id>


ex)

greatlteks:/ $ ps | grep monkey

shell     18286 16512 2142876 110416 futex_wait 74baca4f70 S com.android.commands.monkey

greatlteks:/ $ kill 18286




설정

트랙백

댓글

- 句子

两个月以后可以上市 : 두달 후에 출시 될것이다.

(liǎng gè yuè yǐ hòu kě yǐ shàng shì)

一年给我们一次奖金 : 1년에 우리에게 한번의 성과급을 준다.

(yī nián gěi wǒ men yī cì jiǎng jīn)

声音好听 : 목소리가 좋다.

(shēng yīn hǎo tīng)

亲切地告诉我 : 친절하게 나에게 알려주다.

(hěn qīn qiē de gào sù wǒ)

还没打算 : 아직 계획을 세우지 못했다.

(wǒ hái méi dǎ suàn) 


- 单词

免费(miǎn fèi) : 공짜 

설정

트랙백

댓글

- 句子

昨天我加班了 : 어제 야근을 했었다.

(zuó tiān wǒ jiā bān le)

姿势不太好 : 자세가 좋지 않다.

(zī shì bú tài hǎo)
每天穿扼杀了学生的创意 : 매일 교복을 입는 것은 학생의 창의성억누른다.

(měi tiān chuān xiào fú è shā le xué shēng de chuàng yì)


- 单词

声音(shēng yīn) : 목소리

脖子(bó zǐ) : 목(외부)

嗓子(sǎng zǐ) : 목(내부)

学校(xué xiào) : 학교

扼杀(è shā) : 억누르다.



설정

트랙백

댓글

개요

: 특정 파일을 하나 열어서 해당 내용의 마지막 줄을 삭제하고 거기에 필요한 내용을 다시 쓰는 기능이 필요하다.


조건

- 기존의 파일을 열어 마지막 줄을 제거하고 필요한 줄로 대체하기


Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>  // sync()
 
int main ()
{
    FILE * fp = fopen ("test","r");
    FILE * fptmp = fopen ("test_tmp","rw"); // r mode 가 없을 경우 read 가 되지 않는다!!
    char buffer[20];
    int retry_count = 0;
    int line = 0;
 
    snprintf(buffer, sizeof(buffer)-1, "--retry_count=%d\n", retry_count+1);  
 
    while(fgets(buffer,20,fp) != NULL){ // 해당 파일의 줄의 갯수를 세는 구문
        fprintf(fptmp, buffer); //
        printf("fp %s\n",buffer);
        line++;
    }
    printf("line = %d\n", line);
    fclose (fp);
 
    fp = fopen ("test","w"); // test 에 다시 써주기 위해 mode를 w로 다시 지정
 
    fseek(fptmp,  0, SEEK_SET);
    for(int i = 0; i < line-2; i++){
        fgets(buffer,20,fptmp);
        printf("fptmp %s\n",buffer);
        fprintf(fp, buffer);
    }
    fprintf(fp, "--lastone %d\n", line);
 
    fclose (fp);
    fclose (fptmp);
    return 0;
}



'IT > 기타' 카테고리의 다른 글

Android monkey script 돌리기  (0) 2017.02.07
Thread 간 sync 를 맞춘후 timeout 을 걸어 hang 을 막는다.  (0) 2017.01.30

설정

트랙백

댓글

- 句子

亲戚串门 : 친척 집에 놀러다니다. 

(qīn qī jiā chuàn mén)

去观光 : 관광하다. 

(qù guān guāng)

营业的餐厅 : 영업하는 음식점을 찾다. 

(zhǎo yíng yè de cān tīng)

体重了两公斤 : 체중이 2kg 증가했다. 

(tǐ zhòng zēng le liǎng gōng jīn)

学习外语是一件很快乐的事情 : 외국어를 공부하는 것은 즐거운 일이다. 

(xué xí wài yǔ shì yī jiàn hěn kuài lè de shì qíng)


- 单词

亲戚 [qīnqi] 친척

观光 [guānguāng] 관광하다

称体重 [chēngtǐzhòng] 체중을 달다.

出差 [chūchāi] 출장

설정

트랙백

댓글


목적

: pthread 로 멀티 스레드 간의 sync 를 맞추고 timeout 을 주어 자식 thread 가 종료되지 않았을 경우 timeout 전까지 기다린 후 진행한다.


사전 지식

- Process 와 Thread 의 차이

: 프로세스는 운영체제로 부터 주소공간, 메모리, 파일등을 할당 받으며, 리눅스 시스템에서는 코드영역과 라이브러리는 프로세스간 공유하게 된다.

: 스레드란 한 프로세스 내에서 동작되는 흐름으로 하나의 프로세스당 하나의 스레드가 존재하는데 이를 메인스레드라고 부르고, 여러개의 스레드가 하나의 프로세스 내에 있을 경우 멀티 스레드가 된다.


프로세스(Process)

- 자신만의 고유공간(주소공간, 메모리 etc)을 할당 받음

- 다른 프로세스와 의 통신 구현이 쉽지 않음

스레드(Thread) 

- 다른 스레드와 공간과 자원을 공유(시스템 자원 절약)

- 메모리를 공유하기 때문에 전역변수를 활용하여 스레드간 통신이 용이


- Ptread 함수

pthread_mutex_trylock - Lock 시도 시에 다른 스레드에 이미 Lock 이 되어 있을 경우 대기 하지 않고 return 되는 함수

int nRet = pthread_mutex_trylock(&m_mutex);

if (nRet == EBUSY) {

        return true;

} else if (nRet == EINVAL) {

        PMUTEX_TRACE_ERROR("Failed to try lock mutex: %s\n", strerror(nRet));

} else {

        pthread_mutex_unlock(&m_mutex);

}


TEST CODE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#include <pthread.h>
#include <fcntl.h>
#include <unistd.h>
 
// Mutex와 cond 변수
static bool is_finish = false;
pthread_mutex_t sync_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t  sync_cond  = PTHREAD_COND_INITIALIZER;
 
// 쓰레드 함수
void *test(void *data)
{
    pthread_mutex_lock(&sync_mutex);
    printf("test++\n");
 
    int i=0;
    int a = *(int *)data;
/*
    while(1){
        printf("%d\n", i++);
        sleep(1);
    };
*/
    for (i = 0; i < 5; i++)
    {
        sleep(1);
        printf("%d\n", i);
    }
 
    printf("test--\n");
    pthread_mutex_unlock(&sync_mutex);
    return (void *)(i * 10);
}
 
int main()
{
    printf("main++\n");
    int a = 100;
    pthread_t thread_t;
    // Cond 를 초기화
    pthread_mutex_init(&sync_mutex, NULL);
    pthread_cond_init(&sync_cond, NULL);
 
    int status;
 
    struct timespec ts;
    int s;
 
    // 쓰레드를 생성한다.
    if (pthread_create(&thread_t, NULL, test, (void *)&a) < 0)
    {
        printf("thread create error:");
        exit(0);
    }
     
    sleep(5);   
 
    printf("trylock++\n");
/*
    while(pthread_mutex_trylock(&sync_mutex) == EBUSY){
        if(retry < 0) break;
        sleep(1);
        printf("Thread is busy, wait for 1s retry =%d\n",retry--);
    }
*/
 
    int retry = 5;
    for(int i =0; i < retry; i++){ // 5초의 기다림.
        int rc = pthread_mutex_trylock(&sync_mutex);
        if(rc == EBUSY) {
            printf("Thread is busy, wait for 1s retry =%d\n", i);
        } else if(rc == 0) {
            printf("Child thread is finished!!\n");
            pthread_mutex_unlock(&sync_mutex);
            break; // 자식 Thread 가 종료되었을 경우, for 문을 나가게 됨.
        } else {
            printf("Unexpected error %d\n", rc);
        }
        sleep(1);
    }
    printf("trylock--\n");   
 
    printf("Thread End %d\n", status);
    return 1;
}


그외 Tip

- pthread 를 gcc 로 compile 하기 위해서는 -lpthread 옵션을 주어야 한다.

: ex - gcc -o test test.cpp -lpthread

- clock_gettime 을 gcc 로 complie 하기 위해서는 -lrt 옵션을 주어야 한다.

설정

트랙백

댓글